From: Thomas Gleixner <tglx@linutronix.de>
To: David Carrillo-Cisneros <davidcc@google.com>
Cc: linux-kernel@vger.kernel.org, "x86@kernel.org" <x86@kernel.org>,
Ingo Molnar <mingo@redhat.com>, Andi Kleen <ak@linux.intel.com>,
Kan Liang <kan.liang@intel.com>,
Peter Zijlstra <peterz@infradead.org>,
Vegard Nossum <vegard.nossum@gmail.com>,
Marcelo Tosatti <mtosatti@redhat.com>,
Nilay Vaish <nilayvaish@gmail.com>, Borislav Petkov <bp@suse.de>,
Vikas Shivappa <vikas.shivappa@linux.intel.com>,
Ravi V Shankar <ravi.v.shankar@intel.com>,
Fenghua Yu <fenghua.yu@intel.com>, Paul Turner <pjt@google.com>,
Stephane Eranian <eranian@google.com>
Subject: Re: [PATCH v3 04/46] perf/x86/intel/cmt: add device initialization and CPU hotplug support
Date: Thu, 10 Nov 2016 16:19:06 +0100 (CET) [thread overview]
Message-ID: <alpine.DEB.2.20.1611101442290.3501@nanos> (raw)
In-Reply-To: <1477787923-61185-5-git-send-email-davidcc@google.com>
On Sat, 29 Oct 2016, David Carrillo-Cisneros wrote:
> +static void free_pkg_data(struct pkg_data *pkg_data)
> +{
> + kfree(pkg_data);
> +}
So this is called from __terminate_pkg_data() which itself is called from
some random other place. Is this a code chasing game or is there a
technical reason why functions which belong together are not grouped
together?
> +/* Init pkg_data for @cpu 's package. */
> +static struct pkg_data *alloc_pkg_data(int cpu)
> +{
> + struct cpuinfo_x86 *c = &cpu_data(cpu);
> + struct pkg_data *pkgd;
> + int numa_node = cpu_to_node(cpu);
> + u16 pkgid = topology_logical_package_id(cpu);
Can you please sort the variables in reverse fir tree order?
u16 pkgid = topology_logical_package_id(cpu);
struct cpuinfo_x86 *c = &cpu_data(cpu);
int numa_node = cpu_to_node(cpu);
struct pkg_data *pkgd;
That's way simpler to parse than this random ordering.
> +
> + if (c->x86_cache_occ_scale != cmt_l3_scale) {
And why would c->x86_cache_occ_scale be intialized already when you really
hotplug a CPU? It cannot be initialized because it is done from
identify_cpu() when the cpu actually starts.
You just never noticed because the driver initialized _AFTER_ all the cpus
are brought up and you never bothered to limit the number of cpus which are
brought up at boot time to a single node and then bring up the other node
_after_ loading the driver.
> + /* 0 scale must have been converted to 1 automatically. */
> + if (c->x86_cache_occ_scale || cmt_l3_scale != 1) {
This check will just explode in your face when you do the above because
c->x86_cache_occ_scale is 0.
So IOW. This is broken and the wrong place to do this.
> + pr_err("Multiple LLC scale values, disabling CMT support.\n");
Interesting. You disable CMT support. That's true for init(). In the real
hotplug case you prevent bringing the cpu up, so the message is misleading
because CMT for the already online cpus is already working and keeps so.
> + return ERR_PTR(-ENXIO);
> + }
> + }
> +
> + pkgd = kzalloc_node(sizeof(*pkgd), GFP_KERNEL, numa_node);
> + if (!pkgd)
> + return ERR_PTR(-ENOMEM);
> +
> + pkgd->max_rmid = c->x86_cache_max_rmid;
> +
> + pkgd->work_cpu = cpu;
This is wrong. This want's to be -1 or something invalid. We now can stop
the hotplug process of a CPU at some random state. So if we stop right
after this callback then this not yet online cpu is set as work cpu and if
we then bring up another cpu in the package then it operates with a stale
work cpu. Please make stuff symmetric. The pre online prep stage is just
there to prepare data and pre initialize it. Anything which is related to
operational state has to be done at the point where things become
operational and undone at the same state when going down.
> + pkgd->pkgid = pkgid;
> +
> + __min_max_rmid = min(__min_max_rmid, pkgd->max_rmid);
What protects against the case where rmids are in use already and this cuts
__min_max_rmid short during hotplug?
> +static int init_pkg_data(int cpu)
> +{
> + struct pkg_data *pkgd;
> + u16 pkgid = topology_logical_package_id(cpu);
> +
> + lockdep_assert_held(&cmt_mutex);
> +
> + /* Verify that this pkgid isn't already initialized. */
> + if (WARN_ON_ONCE(cmt_pkgs_data[pkgid]))
> + return -EPERM;
For one this is a direct dereference of something which claims to be rcu
protected. That's inconsistent.
Further this check is completely pointless. This function is called from
intel_cmt_prep_up() after detecting that there is no package data for this
particular package id. I'm all for defensive programming, but this is just
beyond silly.
Aside of that why are you looking up pkgid in three functions in a row
instead of simply handing it from one to the other?
cmt_prep_up() -> init_pkg_data() -> alloc_pkg_data()
> + pkgd = alloc_pkg_data(cpu);
> + if (IS_ERR(pkgd))
> + return PTR_ERR(pkgd);
> +
> + rcu_assign_pointer(cmt_pkgs_data[pkgid], pkgd);
> + synchronize_rcu();
And this synchronize_rcu() is required because of what? This is the first
CPU of a package being brought up and you are holding the cmt_mutex.
I might be missing something, but if so, then this is missing a comment.
> +static int intel_cmt_prep_down(unsigned int cpu)
> +{
> + struct pkg_data *pkgd;
> + u16 pkgid = topology_logical_package_id(cpu);
> +
> + mutex_lock(&cmt_mutex);
> + pkgd = rcu_dereference_protected(cmt_pkgs_data[pkgid],
> + lockdep_is_held(&cmt_mutex));
> + if (pkgd->work_cpu >= nr_cpu_ids) {
> + /* will destroy pkgd */
> + __terminate_pkg_data(pkgd);
Oh right. You free data _BEFORE_ setting the pointer to NULL and
synchronizing RCU. So anything which is merily using rcu_read_lock() can
get a valid reference and fiddle with freed data. Well done.
> + RCU_INIT_POINTER(cmt_pkgs_data[pkgid], NULL);
> + synchronize_rcu();
> +static int __init cmt_start(void)
> +{
> + char *str, scale[20];
> + int err;
> +
> + /* will be modified by init_pkg_data() in intel_cmt_prep_up(). */
> + __min_max_rmid = UINT_MAX;
> + err = cpuhp_setup_state(CPUHP_PERF_X86_CMT_PREP,
> + "PERF_X86_CMT_PREP",
> + intel_cmt_prep_up,
> + intel_cmt_prep_down);
> + if (err)
> + return err;
> +
> + err = cpuhp_setup_state(CPUHP_AP_PERF_X86_CMT_ONLINE,
> + "AP_PERF_X86_CMT_ONLINE",
> + intel_cmt_hp_online_enter,
> + intel_cmt_hp_online_exit);
> + if (err)
> + goto rm_prep;
> +
> + snprintf(scale, sizeof(scale), "%u", cmt_l3_scale);
> + str = kstrdup(scale, GFP_KERNEL);
That string is duplicated for memory leak detector testing purposes or
what?
> + if (!str) {
> + err = -ENOMEM;
> + goto rm_online;
> + }
> +
> + return 0;
> +
> +rm_online:
> + cpuhp_remove_state(CPUHP_AP_PERF_X86_CMT_ONLINE);
> +rm_prep:
> + cpuhp_remove_state(CPUHP_PERF_X86_CMT_PREP);
> +
> + return err;
> +}
> +
> +static int __init intel_cmt_init(void)
> +{
> + struct pkg_data *pkgd = NULL;
> + int err = 0;
> +
> + if (!x86_match_cpu(intel_cmt_match)) {
> + err = -ENODEV;
> + goto err_exit;
This is crap. If a CPU does NOT support this then printing the
registration failed error is just confusing. If it's not supported, return
-ENODEV and be done with it.
> + }
> +
> + err = cmt_alloc();
> + if (err)
> + goto err_exit;
> +
> + err = cmt_start();
> + if (err)
> + goto err_dealloc;
> +
> + pr_info("Intel CMT enabled with ");
> + rcu_read_lock();
> + while ((pkgd = cmt_pkgs_data_next_rcu(pkgd))) {
> + pr_cont("%d RMIDs for pkg %d, ",
> + pkgd->max_rmid + 1, pkgd->pkgid);
And this is useful because? Because it's so nice to have random stuff printed.
The only valuable information is that this is enabled with the detected
possible number of rmids (__min_max_rmid or whatever incomprehensible
variable name you came up with).
> + }
> + rcu_read_unlock();
> + pr_cont("and l3 scale of %d KBs.\n", cmt_l3_scale);
i.e this should be:
pr_info("Intel CMT enabled. %d RMIDs, L3 scale %d KBs", ....);
Am I missing something?
If you really want to print out the per package rmdis, then the only reason
to do so is when they atually differ and that can be done where you do that
min() check.
> +
> +device_initcall(intel_cmt_init);
Oh no. This wants to be a module from the very beginning. No point on
forcing this as builtin for no reason.
Thanks,
tglx
next prev parent reply other threads:[~2016-11-10 15:21 UTC|newest]
Thread overview: 59+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-10-30 0:37 [PATCH v3 00/46] Cache Monitoring Technology (aka CQM) David Carrillo-Cisneros
2016-10-30 0:37 ` [PATCH v3 01/46] perf/x86/intel/cqm: remove previous version of CQM and MBM David Carrillo-Cisneros
2016-10-30 0:37 ` [PATCH v3 02/46] perf/x86/intel: rename CQM cpufeatures to CMT David Carrillo-Cisneros
2016-10-30 0:38 ` [PATCH v3 03/46] x86/intel: add CONFIG_INTEL_RDT_M configuration flag David Carrillo-Cisneros
2016-10-30 0:38 ` [PATCH v3 04/46] perf/x86/intel/cmt: add device initialization and CPU hotplug support David Carrillo-Cisneros
2016-11-10 15:19 ` Thomas Gleixner [this message]
2016-10-30 0:38 ` [PATCH v3 05/46] perf/x86/intel/cmt: add per-package locks David Carrillo-Cisneros
2016-11-10 21:23 ` Thomas Gleixner
2016-11-11 2:22 ` David Carrillo-Cisneros
2016-11-11 7:21 ` Peter Zijlstra
2016-11-11 7:32 ` Ingo Molnar
2016-11-11 9:41 ` Thomas Gleixner
2016-11-11 17:21 ` David Carrillo-Cisneros
2016-11-13 10:58 ` Thomas Gleixner
2016-11-15 4:53 ` David Carrillo-Cisneros
2016-11-16 19:00 ` Thomas Gleixner
2016-10-30 0:38 ` [PATCH v3 06/46] perf/x86/intel/cmt: add intel_cmt pmu David Carrillo-Cisneros
2016-11-10 21:27 ` Thomas Gleixner
2016-10-30 0:38 ` [PATCH v3 07/46] perf/core: add RDT Monitoring attributes to struct hw_perf_event David Carrillo-Cisneros
2016-10-30 0:38 ` [PATCH v3 08/46] perf/x86/intel/cmt: add MONitored Resource (monr) initialization David Carrillo-Cisneros
2016-11-10 23:09 ` Thomas Gleixner
2016-10-30 0:38 ` [PATCH v3 09/46] perf/x86/intel/cmt: add basic monr hierarchy David Carrillo-Cisneros
2016-10-30 0:38 ` [PATCH v3 10/46] perf/x86/intel/cmt: add Package MONitored Resource (pmonr) initialization David Carrillo-Cisneros
2016-10-30 0:38 ` [PATCH v3 11/46] perf/x86/intel/cmt: add cmt_user_flags (uflags) to monr David Carrillo-Cisneros
2016-10-30 0:38 ` [PATCH v3 12/46] perf/x86/intel/cmt: add per-package rmid pools David Carrillo-Cisneros
2016-10-30 0:38 ` [PATCH v3 13/46] perf/x86/intel/cmt: add pmonr's Off and Unused states David Carrillo-Cisneros
2016-10-30 0:38 ` [PATCH v3 14/46] perf/x86/intel/cmt: add Active and Dep_{Idle, Dirty} states David Carrillo-Cisneros
2016-10-30 0:38 ` [PATCH v3 15/46] perf/x86/intel: encapsulate rmid and closid updates in pqr cache David Carrillo-Cisneros
2016-10-30 0:38 ` [PATCH v3 16/46] perf/x86/intel/cmt: set sched rmid and complete pmu start/stop/add/del David Carrillo-Cisneros
2016-10-30 0:38 ` [PATCH v3 17/46] perf/x86/intel/cmt: add uflag CMT_UF_NOLAZY_RMID David Carrillo-Cisneros
2016-10-30 0:38 ` [PATCH v3 18/46] perf/core: add arch_info field to struct perf_cgroup David Carrillo-Cisneros
2016-10-30 0:38 ` [PATCH v3 19/46] perf/x86/intel/cmt: add support for cgroup events David Carrillo-Cisneros
2016-10-30 0:38 ` [PATCH v3 20/46] perf/core: add pmu::event_terminate David Carrillo-Cisneros
2016-10-30 0:38 ` [PATCH v3 21/46] perf/x86/intel/cmt: use newly introduced event_terminate David Carrillo-Cisneros
2016-10-30 0:38 ` [PATCH v3 22/46] perf/x86/intel/cmt: sync cgroups and intel_cmt device start/stop David Carrillo-Cisneros
2016-10-30 0:38 ` [PATCH v3 23/46] perf/core: hooks to add architecture specific features in perf_cgroup David Carrillo-Cisneros
2016-10-30 0:38 ` [PATCH v3 24/46] perf/x86/intel/cmt: add perf_cgroup_arch_css_{online,offline} David Carrillo-Cisneros
2016-10-30 0:38 ` [PATCH v3 25/46] perf/x86/intel/cmt: add monr->flags and CMT_MONR_ZOMBIE David Carrillo-Cisneros
2016-10-30 0:38 ` [PATCH v3 26/46] sched: introduce the finish_arch_pre_lock_switch() scheduler hook David Carrillo-Cisneros
2016-10-30 0:38 ` [PATCH v3 27/46] perf/x86/intel: add pqr cache flags and intel_pqr_ctx_switch David Carrillo-Cisneros
2016-10-30 0:38 ` [PATCH v3 28/46] perf,perf/x86,perf/powerpc,perf/arm,perf/*: add int error return to pmu::read David Carrillo-Cisneros
2016-10-30 0:38 ` [PATCH v3 29/46] perf/x86/intel/cmt: add error handling to intel_cmt_event_read David Carrillo-Cisneros
2016-10-30 0:38 ` [PATCH v3 30/46] perf/x86/intel/cmt: add asynchronous read for task events David Carrillo-Cisneros
2016-10-30 0:38 ` [PATCH v3 31/46] perf/x86/intel/cmt: add subtree read for cgroup events David Carrillo-Cisneros
2016-10-30 0:38 ` [PATCH v3 32/46] perf/core: Add PERF_EV_CAP_READ_ANY_{CPU_,}PKG flags David Carrillo-Cisneros
2016-10-30 0:38 ` [PATCH v3 33/46] perf/x86/intel/cmt: use PERF_EV_CAP_READ_{,CPU_}PKG flags in Intel cmt David Carrillo-Cisneros
2016-10-30 0:38 ` [PATCH v3 34/46] perf/core: introduce PERF_EV_CAP_CGROUP_NO_RECURSION David Carrillo-Cisneros
2016-10-30 0:38 ` [PATCH v3 35/46] perf/x86/intel/cmt: use PERF_EV_CAP_CGROUP_NO_RECURSION in intel_cmt David Carrillo-Cisneros
2016-10-30 0:38 ` [PATCH v3 36/46] perf/core: add perf_event cgroup hooks for subsystem attributes David Carrillo-Cisneros
2016-10-30 0:38 ` [PATCH v3 37/46] perf/x86/intel/cmt: add cont_monitoring to perf cgroup David Carrillo-Cisneros
2016-10-30 0:38 ` [PATCH v3 38/46] perf/x86/intel/cmt: introduce read SLOs for rotation David Carrillo-Cisneros
2016-10-30 0:38 ` [PATCH v3 39/46] perf/x86/intel/cmt: add max_recycle_threshold sysfs attribute David Carrillo-Cisneros
2016-10-30 0:38 ` [PATCH v3 40/46] perf/x86/intel/cmt: add rotation scheduled work David Carrillo-Cisneros
2016-10-30 0:38 ` [PATCH v3 41/46] perf/x86/intel/cmt: add rotation minimum progress SLO David Carrillo-Cisneros
2016-10-30 0:38 ` [PATCH v3 42/46] perf/x86/intel/cmt: add rmid stealing David Carrillo-Cisneros
2016-10-30 0:38 ` [PATCH v3 43/46] perf/x86/intel/cmt: add CMT_UF_NOSTEAL_RMID flag David Carrillo-Cisneros
2016-10-30 0:38 ` [PATCH v3 44/46] perf/x86/intel/cmt: add debugfs intel_cmt directory David Carrillo-Cisneros
2016-10-30 0:38 ` [PATCH v3 45/46] perf/stat: fix bug in handling events in error state David Carrillo-Cisneros
2016-10-30 0:38 ` [PATCH v3 46/46] perf/stat: revamp read error handling, snapshot and per_pkg events David Carrillo-Cisneros
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=alpine.DEB.2.20.1611101442290.3501@nanos \
--to=tglx@linutronix.de \
--cc=ak@linux.intel.com \
--cc=bp@suse.de \
--cc=davidcc@google.com \
--cc=eranian@google.com \
--cc=fenghua.yu@intel.com \
--cc=kan.liang@intel.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=mtosatti@redhat.com \
--cc=nilayvaish@gmail.com \
--cc=peterz@infradead.org \
--cc=pjt@google.com \
--cc=ravi.v.shankar@intel.com \
--cc=vegard.nossum@gmail.com \
--cc=vikas.shivappa@linux.intel.com \
--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®