From nobody Sat Feb 7 17:54:44 2026 Received: from out-177.mta0.migadu.com (out-177.mta0.migadu.com [91.218.175.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7B101227EBB for ; Mon, 7 Apr 2025 08:54:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.177 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744016100; cv=none; b=cxY1uBdS2BvnGO9Xg9OpspHgJSfqfVgdNNIXoJ9RboFfuzU7m6cEnJ7PHFpH2bAUMZubhkmuiaMwtWPSpIZ4VK89Ap52OEMG7DhpO50X5W5GG6momPo3C926ZAJpuo/D92P8e7Bj9FXCN41yYmAfw6Z1n0mkVnqxucJc2hmq7vs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744016100; c=relaxed/simple; bh=S/krgJ47mHcWOwClo3HTb0co93o+dijfVcRLgxutwHk=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=m2Wh3TfqicnAuoKbSlP927FYylYiY9UwTpoR/PIfdaQuuKStISv8B0Q+dQTQze6BssaSQ2M4RUSCr9WcfDqBhBcBcy8s1kUJrQfI483QCstq377lA/qQu2n4jJUdWZXeC5qr4zLAk7C5uTDfGe8i8mu+YGAx3yp0ZydlS82/Vjo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=eCwmTJwu; arc=none smtp.client-ip=91.218.175.177 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="eCwmTJwu" X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1744016086; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=uZTCm0LxWsnE3tYH357Upfibjs77OsM/NB9Y2oX27PE=; b=eCwmTJwuriVtW9CejDnYuY98GUudC4abWzVHy9TV+D7BtP+GbflTsGpyfc0MyEYJgdQ1CI LWJ3meLEcrI7BlwoQHM241nrKkwNN6T1W6A5yuKVIAzGAPUGWi1cU+FDs66nS67pJ2CfYY BvxW+WaWc40WmTORz7ew4G7QvGBqHCc= From: Thorsten Blum To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , "Liang, Kan" , Thomas Gleixner , Borislav Petkov , Dave Hansen , x86@kernel.org, "H. Peter Anvin" Cc: Thorsten Blum , Ingo Molnar , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2] perf/x86: Rename local bts_buffer variables Date: Mon, 7 Apr 2025 10:52:53 +0200 Message-ID: <20250407085253.742834-2-thorsten.blum@linux.dev> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Migadu-Flow: FLOW_OUT Content-Type: text/plain; charset="utf-8" Rename struct bts_buffer objects from 'buf' to 'bb' to improve the readability when accessing the structure's 'buf' member. For example, 'buf->buf[]' becomes 'bb->buf[]'. Indent line 327 using tabs to silence a checkpatch warning. No functional changes intended. Suggested-by: Ingo Molnar Signed-off-by: Thorsten Blum --- Changes in v2: - struct_size() change should be a separate patch as suggested by Peter - Link to v1: https://lore.kernel.org/lkml/20250331122938.1837255-2-thorste= n.blum@linux.dev/ --- arch/x86/events/intel/bts.c | 144 ++++++++++++++++++------------------ 1 file changed, 72 insertions(+), 72 deletions(-) diff --git a/arch/x86/events/intel/bts.c b/arch/x86/events/intel/bts.c index a95e6c91c4d7..16bc89c8023b 100644 --- a/arch/x86/events/intel/bts.c +++ b/arch/x86/events/intel/bts.c @@ -80,54 +80,54 @@ static void * bts_buffer_setup_aux(struct perf_event *event, void **pages, int nr_pages, bool overwrite) { - struct bts_buffer *buf; + struct bts_buffer *bb; struct page *page; int cpu =3D event->cpu; int node =3D (cpu =3D=3D -1) ? cpu : cpu_to_node(cpu); unsigned long offset; size_t size =3D nr_pages << PAGE_SHIFT; - int pg, nbuf, pad; + int pg, nr_buf, pad; =20 /* count all the high order buffers */ - for (pg =3D 0, nbuf =3D 0; pg < nr_pages;) { + for (pg =3D 0, nr_buf =3D 0; pg < nr_pages;) { page =3D virt_to_page(pages[pg]); pg +=3D buf_nr_pages(page); - nbuf++; + nr_buf++; } =20 /* * to avoid interrupts in overwrite mode, only allow one physical */ - if (overwrite && nbuf > 1) + if (overwrite && nr_buf > 1) return NULL; =20 - buf =3D kzalloc_node(offsetof(struct bts_buffer, buf[nbuf]), GFP_KERNEL, = node); - if (!buf) + bb =3D kzalloc_node(offsetof(struct bts_buffer, buf[nr_buf]), GFP_KERNEL,= node); + if (!bb) return NULL; =20 - buf->nr_pages =3D nr_pages; - buf->nr_bufs =3D nbuf; - buf->snapshot =3D overwrite; - buf->data_pages =3D pages; - buf->real_size =3D size - size % BTS_RECORD_SIZE; + bb->nr_pages =3D nr_pages; + bb->nr_bufs =3D nr_buf; + bb->snapshot =3D overwrite; + bb->data_pages =3D pages; + bb->real_size =3D size - size % BTS_RECORD_SIZE; =20 - for (pg =3D 0, nbuf =3D 0, offset =3D 0, pad =3D 0; nbuf < buf->nr_bufs; = nbuf++) { + for (pg =3D 0, nr_buf =3D 0, offset =3D 0, pad =3D 0; nr_buf < bb->nr_buf= s; nr_buf++) { unsigned int __nr_pages; =20 page =3D virt_to_page(pages[pg]); __nr_pages =3D buf_nr_pages(page); - buf->buf[nbuf].page =3D page; - buf->buf[nbuf].offset =3D offset; - buf->buf[nbuf].displacement =3D (pad ? BTS_RECORD_SIZE - pad : 0); - buf->buf[nbuf].size =3D buf_size(page) - buf->buf[nbuf].displacement; - pad =3D buf->buf[nbuf].size % BTS_RECORD_SIZE; - buf->buf[nbuf].size -=3D pad; + bb->buf[nr_buf].page =3D page; + bb->buf[nr_buf].offset =3D offset; + bb->buf[nr_buf].displacement =3D (pad ? BTS_RECORD_SIZE - pad : 0); + bb->buf[nr_buf].size =3D buf_size(page) - bb->buf[nr_buf].displacement; + pad =3D bb->buf[nr_buf].size % BTS_RECORD_SIZE; + bb->buf[nr_buf].size -=3D pad; =20 pg +=3D __nr_pages; offset +=3D __nr_pages << PAGE_SHIFT; } =20 - return buf; + return bb; } =20 static void bts_buffer_free_aux(void *data) @@ -135,25 +135,25 @@ static void bts_buffer_free_aux(void *data) kfree(data); } =20 -static unsigned long bts_buffer_offset(struct bts_buffer *buf, unsigned in= t idx) +static unsigned long bts_buffer_offset(struct bts_buffer *bb, unsigned int= idx) { - return buf->buf[idx].offset + buf->buf[idx].displacement; + return bb->buf[idx].offset + bb->buf[idx].displacement; } =20 static void -bts_config_buffer(struct bts_buffer *buf) +bts_config_buffer(struct bts_buffer *bb) { int cpu =3D raw_smp_processor_id(); struct debug_store *ds =3D per_cpu(cpu_hw_events, cpu).ds; - struct bts_phys *phys =3D &buf->buf[buf->cur_buf]; + struct bts_phys *phys =3D &bb->buf[bb->cur_buf]; unsigned long index, thresh =3D 0, end =3D phys->size; struct page *page =3D phys->page; =20 - index =3D local_read(&buf->head); + index =3D local_read(&bb->head); =20 - if (!buf->snapshot) { - if (buf->end < phys->offset + buf_size(page)) - end =3D buf->end - phys->offset - phys->displacement; + if (!bb->snapshot) { + if (bb->end < phys->offset + buf_size(page)) + end =3D bb->end - phys->offset - phys->displacement; =20 index -=3D phys->offset + phys->displacement; =20 @@ -168,7 +168,7 @@ bts_config_buffer(struct bts_buffer *buf) ds->bts_buffer_base =3D (u64)(long)page_address(page) + phys->displacemen= t; ds->bts_index =3D ds->bts_buffer_base + index; ds->bts_absolute_maximum =3D ds->bts_buffer_base + end; - ds->bts_interrupt_threshold =3D !buf->snapshot + ds->bts_interrupt_threshold =3D !bb->snapshot ? ds->bts_buffer_base + thresh : ds->bts_absolute_maximum + BTS_RECORD_SIZE; } @@ -184,16 +184,16 @@ static void bts_update(struct bts_ctx *bts) { int cpu =3D raw_smp_processor_id(); struct debug_store *ds =3D per_cpu(cpu_hw_events, cpu).ds; - struct bts_buffer *buf =3D perf_get_aux(&bts->handle); + struct bts_buffer *bb =3D perf_get_aux(&bts->handle); unsigned long index =3D ds->bts_index - ds->bts_buffer_base, old, head; =20 - if (!buf) + if (!bb) return; =20 - head =3D index + bts_buffer_offset(buf, buf->cur_buf); - old =3D local_xchg(&buf->head, head); + head =3D index + bts_buffer_offset(bb, bb->cur_buf); + old =3D local_xchg(&bb->head, head); =20 - if (!buf->snapshot) { + if (!bb->snapshot) { if (old =3D=3D head) return; =20 @@ -205,9 +205,9 @@ static void bts_update(struct bts_ctx *bts) * old and head are always in the same physical buffer, so we * can subtract them to get the data size. */ - local_add(head - old, &buf->data_size); + local_add(head - old, &bb->data_size); } else { - local_set(&buf->data_size, head); + local_set(&bb->data_size, head); } =20 /* @@ -218,7 +218,7 @@ static void bts_update(struct bts_ctx *bts) } =20 static int -bts_buffer_reset(struct bts_buffer *buf, struct perf_output_handle *handle= ); +bts_buffer_reset(struct bts_buffer *bb, struct perf_output_handle *handle); =20 /* * Ordering PMU callbacks wrt themselves and the PMI is done by means @@ -232,17 +232,17 @@ bts_buffer_reset(struct bts_buffer *buf, struct perf_= output_handle *handle); static void __bts_event_start(struct perf_event *event) { struct bts_ctx *bts =3D this_cpu_ptr(bts_ctx); - struct bts_buffer *buf =3D perf_get_aux(&bts->handle); + struct bts_buffer *bb =3D perf_get_aux(&bts->handle); u64 config =3D 0; =20 - if (!buf->snapshot) + if (!bb->snapshot) config |=3D ARCH_PERFMON_EVENTSEL_INT; if (!event->attr.exclude_kernel) config |=3D ARCH_PERFMON_EVENTSEL_OS; if (!event->attr.exclude_user) config |=3D ARCH_PERFMON_EVENTSEL_USR; =20 - bts_config_buffer(buf); + bts_config_buffer(bb); =20 /* * local barrier to make sure that ds configuration made it @@ -261,13 +261,13 @@ static void bts_event_start(struct perf_event *event,= int flags) { struct cpu_hw_events *cpuc =3D this_cpu_ptr(&cpu_hw_events); struct bts_ctx *bts =3D this_cpu_ptr(bts_ctx); - struct bts_buffer *buf; + struct bts_buffer *bb; =20 - buf =3D perf_aux_output_begin(&bts->handle, event); - if (!buf) + bb =3D perf_aux_output_begin(&bts->handle, event); + if (!bb) goto fail_stop; =20 - if (bts_buffer_reset(buf, &bts->handle)) + if (bts_buffer_reset(bb, &bts->handle)) goto fail_end_stop; =20 bts->ds_back.bts_buffer_base =3D cpuc->ds->bts_buffer_base; @@ -306,27 +306,27 @@ static void bts_event_stop(struct perf_event *event, = int flags) { struct cpu_hw_events *cpuc =3D this_cpu_ptr(&cpu_hw_events); struct bts_ctx *bts =3D this_cpu_ptr(bts_ctx); - struct bts_buffer *buf =3D NULL; + struct bts_buffer *bb =3D NULL; int state =3D READ_ONCE(bts->state); =20 if (state =3D=3D BTS_STATE_ACTIVE) __bts_event_stop(event, BTS_STATE_STOPPED); =20 if (state !=3D BTS_STATE_STOPPED) - buf =3D perf_get_aux(&bts->handle); + bb =3D perf_get_aux(&bts->handle); =20 event->hw.state |=3D PERF_HES_STOPPED; =20 if (flags & PERF_EF_UPDATE) { bts_update(bts); =20 - if (buf) { - if (buf->snapshot) + if (bb) { + if (bb->snapshot) bts->handle.head =3D - local_xchg(&buf->data_size, - buf->nr_pages << PAGE_SHIFT); + local_xchg(&bb->data_size, + bb->nr_pages << PAGE_SHIFT); perf_aux_output_end(&bts->handle, - local_xchg(&buf->data_size, 0)); + local_xchg(&bb->data_size, 0)); } =20 cpuc->ds->bts_index =3D bts->ds_back.bts_buffer_base; @@ -382,19 +382,19 @@ void intel_bts_disable_local(void) } =20 static int -bts_buffer_reset(struct bts_buffer *buf, struct perf_output_handle *handle) +bts_buffer_reset(struct bts_buffer *bb, struct perf_output_handle *handle) { unsigned long head, space, next_space, pad, gap, skip, wakeup; unsigned int next_buf; struct bts_phys *phys, *next_phys; int ret; =20 - if (buf->snapshot) + if (bb->snapshot) return 0; =20 - head =3D handle->head & ((buf->nr_pages << PAGE_SHIFT) - 1); + head =3D handle->head & ((bb->nr_pages << PAGE_SHIFT) - 1); =20 - phys =3D &buf->buf[buf->cur_buf]; + phys =3D &bb->buf[bb->cur_buf]; space =3D phys->offset + phys->displacement + phys->size - head; pad =3D space; if (space > handle->size) { @@ -403,10 +403,10 @@ bts_buffer_reset(struct bts_buffer *buf, struct perf_= output_handle *handle) } if (space <=3D BTS_SAFETY_MARGIN) { /* See if next phys buffer has more space */ - next_buf =3D buf->cur_buf + 1; - if (next_buf >=3D buf->nr_bufs) + next_buf =3D bb->cur_buf + 1; + if (next_buf >=3D bb->nr_bufs) next_buf =3D 0; - next_phys =3D &buf->buf[next_buf]; + next_phys =3D &bb->buf[next_buf]; gap =3D buf_size(phys->page) - phys->displacement - phys->size + next_phys->displacement; skip =3D pad + gap; @@ -431,8 +431,8 @@ bts_buffer_reset(struct bts_buffer *buf, struct perf_ou= tput_handle *handle) * anymore, so we must not be racing with * bts_update(). */ - buf->cur_buf =3D next_buf; - local_set(&buf->head, head); + bb->cur_buf =3D next_buf; + local_set(&bb->head, head); } } } @@ -445,7 +445,7 @@ bts_buffer_reset(struct bts_buffer *buf, struct perf_ou= tput_handle *handle) space -=3D space % BTS_RECORD_SIZE; } =20 - buf->end =3D head + space; + bb->end =3D head + space; =20 /* * If we have no space, the lost notification would have been sent when @@ -462,7 +462,7 @@ int intel_bts_interrupt(void) struct debug_store *ds =3D this_cpu_ptr(&cpu_hw_events)->ds; struct bts_ctx *bts; struct perf_event *event; - struct bts_buffer *buf; + struct bts_buffer *bb; s64 old_head; int err =3D -ENOSPC, handled =3D 0; =20 @@ -485,8 +485,8 @@ int intel_bts_interrupt(void) if (READ_ONCE(bts->state) =3D=3D BTS_STATE_STOPPED) return handled; =20 - buf =3D perf_get_aux(&bts->handle); - if (!buf) + bb =3D perf_get_aux(&bts->handle); + if (!bb) return handled; =20 /* @@ -494,26 +494,26 @@ int intel_bts_interrupt(void) * there's no other way of telling, because the pointer will * keep moving */ - if (buf->snapshot) + if (bb->snapshot) return 0; =20 - old_head =3D local_read(&buf->head); + old_head =3D local_read(&bb->head); bts_update(bts); =20 /* no new data */ - if (old_head =3D=3D local_read(&buf->head)) + if (old_head =3D=3D local_read(&bb->head)) return handled; =20 - perf_aux_output_end(&bts->handle, local_xchg(&buf->data_size, 0)); + perf_aux_output_end(&bts->handle, local_xchg(&bb->data_size, 0)); =20 - buf =3D perf_aux_output_begin(&bts->handle, event); - if (buf) - err =3D bts_buffer_reset(buf, &bts->handle); + bb =3D perf_aux_output_begin(&bts->handle, event); + if (bb) + err =3D bts_buffer_reset(bb, &bts->handle); =20 if (err) { WRITE_ONCE(bts->state, BTS_STATE_STOPPED); =20 - if (buf) { + if (bb) { /* * BTS_STATE_STOPPED should be visible before * cleared handle::event --=20 2.49.0