mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Mi, Dapeng" <dapeng1.mi@linux.intel.com>
To: Ian Rogers <irogers@google.com>, Rosen Penev <rosenp@gmail.com>
Cc: linux-perf-users@vger.kernel.org,
	Peter Zijlstra <peterz@infradead.org>,
	Ingo Molnar <mingo@redhat.com>,
	Arnaldo Carvalho de Melo <acme@kernel.org>,
	Namhyung Kim <namhyung@kernel.org>,
	Mark Rutland <mark.rutland@arm.com>,
	Alexander Shishkin <alexander.shishkin@linux.intel.com>,
	Jiri Olsa <jolsa@kernel.org>,
	Adrian Hunter <adrian.hunter@intel.com>,
	James Clark <james.clark@linaro.org>,
	Thomas Gleixner <tglx@kernel.org>, Borislav Petkov <bp@alien8.de>,
	Dave Hansen <dave.hansen@linux.intel.com>,
	"maintainer:X86 ARCHITECTURE (32-BIT AND 64-BIT)"
	<x86@kernel.org>, "H. Peter Anvin" <hpa@zytor.com>,
	"open list:PERFORMANCE EVENTS SUBSYSTEM"
	<linux-kernel@vger.kernel.org>
Subject: Re: [PATCH] perf/x86/amd/uncore: turn amd_uncore_ctx events into a flexible array
Date: Wed, 16 Sep 2026 08:14:53 +0800	[thread overview]
Message-ID: <e812551f-8323-461e-a8ce-34551988f7c5@linux.intel.com> (raw)
In-Reply-To: <CAP-5=fXyyj6w1mR71B6e+j7sV9GA-Gs1ibfp5pCuY6T+W+xWjQ@mail.gmail.com>


On 9/16/2026 4:58 AM, Ian Rogers wrote:
> On Fri, May 22, 2026 at 6:19 PM Rosen Penev <rosenp@gmail.com> wrote:
>> The events pointer was kzalloc_node()'d immediately after the parent
>> struct allocation, with the count (pmu->num_counters) trivially
>> available beforehand.  Move events to the struct tail as a flexible
>> array member and fold the two allocations into a single kzalloc_node()
>> with struct_size(), dropping the separate kfree(ctx->events) in the
>> free path.
>>
>> Assisted-by: Claude:Opus-4.7
>> Signed-off-by: Rosen Penev <rosenp@gmail.com>
>> ---
>>  arch/x86/events/amd/uncore.c | 15 +++------------
>>  1 file changed, 3 insertions(+), 12 deletions(-)
>>
>> diff --git a/arch/x86/events/amd/uncore.c b/arch/x86/events/amd/uncore.c
>> index 05cff39968ec..0e265fc1fef8 100644
>> --- a/arch/x86/events/amd/uncore.c
>> +++ b/arch/x86/events/amd/uncore.c
>> @@ -39,11 +39,11 @@ static int pmu_version;
>>  struct amd_uncore_ctx {
>>         int refcnt;
>>         int cpu;
>> -       struct perf_event **events;
>>         unsigned long active_mask[BITS_TO_LONGS(NUM_COUNTERS_MAX)];
>>         int nr_active;
>>         struct hrtimer hrtimer;
>>         u64 hrtimer_duration;
>> +       struct perf_event *events[];
> As the number of counters is fixed and events doesn't grow, this makes
> sense to me. Dapeng, what do you think?
It looks good to me. But it seems there is no Sashikio review, so better
resend to trigger Sashiko review for double check. Thanks.


>
> Thanks,
> Ian
>
>>  };
>>
>>  struct amd_uncore_pmu {
>> @@ -488,10 +488,8 @@ static void amd_uncore_ctx_free(struct amd_uncore *uncore, unsigned int cpu)
>>                 if (cpu == ctx->cpu)
>>                         cpumask_clear_cpu(cpu, &pmu->active_mask);
>>
>> -               if (!--ctx->refcnt) {
>> -                       kfree(ctx->events);
>> +               if (!--ctx->refcnt)
>>                         kfree(ctx);
>> -               }
>>
>>                 *per_cpu_ptr(pmu->ctx, cpu) = NULL;
>>         }
>> @@ -536,18 +534,11 @@ static int amd_uncore_ctx_init(struct amd_uncore *uncore, unsigned int cpu)
>>                 /* Allocate context if sibling does not exist */
>>                 if (!curr) {
>>                         node = cpu_to_node(cpu);
>> -                       curr = kzalloc_node(sizeof(*curr), GFP_KERNEL, node);
>> +                       curr = kzalloc_node(struct_size(curr, events, pmu->num_counters), GFP_KERNEL, node);
>>                         if (!curr)
>>                                 goto fail;
>>
>>                         curr->cpu = cpu;
>> -                       curr->events = kzalloc_node(sizeof(*curr->events) *
>> -                                                   pmu->num_counters,
>> -                                                   GFP_KERNEL, node);
>> -                       if (!curr->events) {
>> -                               kfree(curr);
>> -                               goto fail;
>> -                       }
>>
>>                         amd_uncore_init_hrtimer(curr);
>>                         curr->hrtimer_duration = (u64)update_interval * NSEC_PER_MSEC;
>> --
>> 2.54.0
>>

      reply	other threads:[~2026-09-16  0:15 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-05-23  1:19 Rosen Penev
2026-09-15 20:58 ` Ian Rogers
2026-09-16  0:14   ` Mi, Dapeng [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=e812551f-8323-461e-a8ce-34551988f7c5@linux.intel.com \
    --to=dapeng1.mi@linux.intel.com \
    --cc=acme@kernel.org \
    --cc=adrian.hunter@intel.com \
    --cc=alexander.shishkin@linux.intel.com \
    --cc=bp@alien8.de \
    --cc=dave.hansen@linux.intel.com \
    --cc=hpa@zytor.com \
    --cc=irogers@google.com \
    --cc=james.clark@linaro.org \
    --cc=jolsa@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-perf-users@vger.kernel.org \
    --cc=mark.rutland@arm.com \
    --cc=mingo@redhat.com \
    --cc=namhyung@kernel.org \
    --cc=peterz@infradead.org \
    --cc=rosenp@gmail.com \
    --cc=tglx@kernel.org \
    --cc=x86@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®