From: Sebastian Siewior <bigeasy@linutronix.de>
To: Anna-Maria Behnsen <anna-maria@linutronix.de>
Cc: linux-kernel@vger.kernel.org,
Peter Zijlstra <peterz@infradead.org>,
John Stultz <jstultz@google.com>,
Thomas Gleixner <tglx@linutronix.de>,
Eric Dumazet <edumazet@google.com>,
"Rafael J . Wysocki" <rafael.j.wysocki@intel.com>,
Arjan van de Ven <arjan@infradead.org>,
"Paul E . McKenney" <paulmck@kernel.org>,
Frederic Weisbecker <frederic@kernel.org>,
Rik van Riel <riel@surriel.com>,
Steven Rostedt <rostedt@goodmis.org>,
Giovanni Gherdovich <ggherdovich@suse.cz>,
Lukasz Luba <lukasz.luba@arm.com>,
"Gautham R . Shenoy" <gautham.shenoy@amd.com>,
Srinivas Pandruvada <srinivas.pandruvada@intel.com>,
K Prateek Nayak <kprateek.nayak@amd.com>
Subject: Re: [PATCH v9 30/32] timers: Implement the hierarchical pull model
Date: Tue, 12 Dec 2023 13:14:04 +0100 [thread overview]
Message-ID: <20231212121404.C2R9VWj1@linutronix.de> (raw)
In-Reply-To: <20231201092654.34614-31-anna-maria@linutronix.de>
On 2023-12-01 10:26:52 [+0100], Anna-Maria Behnsen wrote:
> diff --git a/kernel/time/timer_migration.c b/kernel/time/timer_migration.c
> new file mode 100644
> index 000000000000..05cd8f1bc45d
> --- /dev/null
> +++ b/kernel/time/timer_migration.c
> @@ -0,0 +1,1636 @@
…
> +static int __init tmigr_init(void)
> +{
> + unsigned int cpulvl, nodelvl, cpus_per_node, i;
> + unsigned int nnodes = num_possible_nodes();
> + unsigned int ncpus = num_possible_cpus();
> + int ret = -ENOMEM;
> +
> + /* Nothing to do if running on UP */
> + if (ncpus == 1)
> + return 0;
> +
> + /*
> + * Calculate the required hierarchy levels. Unfortunately there is no
> + * reliable information available, unless all possible CPUs have been
> + * brought up and all numa nodes are populated.
NUMA
> + *
> + * Estimate the number of levels with the number of possible nodes and
> + * the number of possible CPUs. Assume CPUs are spread evenly across
> + * nodes. We cannot rely on cpumask_of_node() because there only already
> + * online CPUs are considered.
> + */
We cannot rely on cpumask_of_node() because it only works for online
CPUs.
> + cpus_per_node = DIV_ROUND_UP(ncpus, nnodes);
> +
> + /* Calc the hierarchy levels required to hold the CPUs of a node */
> + cpulvl = DIV_ROUND_UP(order_base_2(cpus_per_node),
> + ilog2(TMIGR_CHILDREN_PER_GROUP));
> +
> + /* Calculate the extra levels to connect all nodes */
> + nodelvl = DIV_ROUND_UP(order_base_2(nnodes),
> + ilog2(TMIGR_CHILDREN_PER_GROUP));
> +
> + tmigr_hierarchy_levels = cpulvl + nodelvl;
> +
> + /*
> + * If a numa node spawns more than one CPU level group then the next
NUMA
> + * level(s) of the hierarchy contains groups which handle all CPU groups
> + * of the same numa node. The level above goes across numa nodes. Store
NUMA
> + * this information for the setup code to decide when node matching is
> + * not longer required.
s/not longer/no longer ?
> + */
> + tmigr_crossnode_level = cpulvl;
> +
> + tmigr_level_list = kcalloc(tmigr_hierarchy_levels, sizeof(struct list_head), GFP_KERNEL);
> + if (!tmigr_level_list)
> + goto err;
> +
> + for (i = 0; i < tmigr_hierarchy_levels; i++)
> + INIT_LIST_HEAD(&tmigr_level_list[i]);
> +
> + pr_info("Timer migration: %d hierarchy levels; %d children per group;"
> + " %d crossnode level\n",
> + tmigr_hierarchy_levels, TMIGR_CHILDREN_PER_GROUP,
> + tmigr_crossnode_level);
> +
> + ret = cpuhp_setup_state(CPUHP_AP_TMIGR_ONLINE, "tmigr:online",
> + tmigr_cpu_online, tmigr_cpu_offline);
> + if (ret)
> + goto err;
> +
> + return 0;
> +
> +err:
> + pr_err("Timer migration setup failed\n");
> + return ret;
> +}
> +late_initcall(tmigr_init);
> diff --git a/kernel/time/timer_migration.h b/kernel/time/timer_migration.h
> new file mode 100644
> index 000000000000..260b87e5708d
> --- /dev/null
> +++ b/kernel/time/timer_migration.h
> @@ -0,0 +1,144 @@
> +/* SPDX-License-Identifier: GPL-2.0-only */
> +#ifndef _KERNEL_TIME_MIGRATION_H
> +#define _KERNEL_TIME_MIGRATION_H
> +
> +/* Per group capacity. Must be a power of 2! */
> +#define TMIGR_CHILDREN_PER_GROUP 8
BUILD_BUG_ON_NOT_POWER_OF_2(TMIGR_CHILDREN_PER_GROUP)
Maybe in the .c file.
> +/**
> + * struct tmigr_event - a timer event associated to a CPU
> + * @nextevt: The node to enqueue an event in the parent group queue
> + * @cpu: The CPU to which this event belongs
> + * @ignore: Hint whether the event could be ignored; it is set when
> + * CPU or group is active;
> + */
> +struct tmigr_event {
> + struct timerqueue_node nextevt;
> + unsigned int cpu;
> + bool ignore;
> +};
> +
> +/**
> + * struct tmigr_group - timer migration hierarchy group
> + * @lock: Lock protecting the event information and group hierarchy
> + * information during setup
> + * @migr_state: State of the group (see union tmigr_state)
So the lock does not protect migr_state? Mind moving it a little down the
road? Not only would it be more obvious what is protected by the lock
but it would also move migr_state in another/ later cache line.
> + * @parent: Pointer to the parent group
> + * @groupevt: Next event of the group which is only used when the
> + * group is !active. The group event is then queued into
> + * the parent timer queue.
> + * Ignore bit of @groupevt is set when the group is active.
> + * @next_expiry: Base monotonic expiry time of the next event of the
> + * group; It is used for the racy lockless check whether a
> + * remote expiry is required; it is always reliable
> + * @events: Timer queue for child events queued in the group
> + * @childmask: childmask of the group in the parent group; is set
> + * during setup and will never change; could be read
_can_ be read lockless.
> + * lockless
> + * @level: Hierarchy level of the group; Required during setup
> + * @list: List head that is added to the per level
> + * tmigr_level_list; is required during setup when a
> + * new group needs to be connected to the existing
> + * hierarchy groups
> + * @numa_node: Is set to numa node when level < tmigr_crossnode_level;
NUMA
(as long as the group level is per NUMA node).
> + * otherwise it is set to NUMA_NO_NODE; Required for
> + * setup only to make sure CPUs and groups are per
> + * numa node as long as level < tmigr_crossnode_level
… to make sure CPU and group information is NUMA local. This is
true until the top most hierarchy level (level <
tmigr_crossnode_level).
> + * @num_children: Counter of group children to make sure the group is only
> + * filled with TMIGR_CHILDREN_PER_GROUP; Required for setup
> + * only
> + */
> +struct tmigr_group {
> + raw_spinlock_t lock;
> + atomic_t migr_state;
> + struct tmigr_group *parent;
> + struct tmigr_event groupevt;
> + u64 next_expiry;
> + struct timerqueue_head events;
> + u8 childmask;
> + unsigned int level;
> + struct list_head list;
> + int numa_node;
> + unsigned int num_children;
> +};
> +
> +/**
> + * struct tmigr_cpu - timer migration per CPU group
> + * @lock: Lock protecting the tmigr_cpu group information
> + * @online: Indicates whether the CPU is online; In deactivate path
> + * it is required to know whether the migrator in the top
> + * level group is on the way to go offline when a timer is
level group, which is to be set offline, while a timer is pending.
> + * pending. Then another online CPU needs to be rescheduled
> + * to make sure the timers are handled properly;
Then another online CPU needs to be notified to take over the
migrator role.
The "rescheduled" part sounds like the current implementation.
> + * Furthermore the information is required in CPU hotplug
> + * path as the CPU is able to go idle before the timer
> + * migration hierarchy hotplug AP is reached. During this
> + * phase, the CPU has to handle the global timers by its
s/by its own/on its own/
> + * own and does not act as a migrator.
s/does not/must not
> + * @idle: Indicates whether the CPU is idle in the timer migration
> + * hierarchy
> + * @remote: Is set when timers of the CPU are expired remote
s/remote/remotely
> + * @wakeup_recalc: Indicates, whether a recalculation of the @wakeup value
> + * is required. It is only used when the CPU is marked idle
> + * in the timer migration hierarchy.
What does `It' refer to? Is it `wakeup_recalc' or `wakeup' ?
> + * @tmgroup: Pointer to the parent group
> + * @childmask: childmask of tmigr_cpu in the parent group
> + * @wakeup: Stores the first timer when the timer migration
> + * hierarchy is completely idle and remote expiry was done;
> + * is returned to timer code in the idle path; it is only
is used in the idle path only (what is the idle path (probably
obvious))
> + * valid, when @wakeup_recalc is not set
> + * @cpuevt: CPU event which could be queued into the parent group
I don't know why but it feels like s/queued/enqueued/g
But it might be a British vs American thing.
Sebastian
next prev parent reply other threads:[~2023-12-12 12:14 UTC|newest]
Thread overview: 86+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-12-01 9:26 [PATCH v9 00/32] timers: Move from a push remote at enqueue to a pull at expiry model Anna-Maria Behnsen
2023-12-01 9:26 ` [PATCH v9 01/32] tick-sched: Fix function names in comments Anna-Maria Behnsen
2023-12-20 13:09 ` Frederic Weisbecker
2023-12-20 15:59 ` [tip: timers/core] " tip-bot2 for Anna-Maria Behnsen
2023-12-01 9:26 ` [PATCH v9 02/32] tick/sched: Cleanup confusing variables Anna-Maria Behnsen
2023-12-20 15:59 ` [tip: timers/core] " tip-bot2 for Anna-Maria Behnsen
2023-12-01 9:26 ` [PATCH v9 03/32] tick-sched: Warn when next tick seems to be in the past Anna-Maria Behnsen
2023-12-20 13:27 ` Frederic Weisbecker
2023-12-20 15:59 ` [tip: timers/core] " tip-bot2 for Anna-Maria Behnsen
2023-12-01 9:26 ` [PATCH v9 04/32] tracing/timers: Enhance timer_start tracepoint Anna-Maria Behnsen
2023-12-20 13:35 ` Frederic Weisbecker
2023-12-20 15:59 ` [tip: timers/core] " tip-bot2 for Anna-Maria Behnsen
2023-12-01 9:26 ` [PATCH v9 05/32] tracing/timers: Add tracepoint for tracking timer base is_idle flag Anna-Maria Behnsen
2023-12-20 13:43 ` Frederic Weisbecker
2023-12-20 15:59 ` [tip: timers/core] " tip-bot2 for Anna-Maria Behnsen
2023-12-01 9:26 ` [PATCH v9 06/32] timers: Do not IPI for deferrable timers Anna-Maria Behnsen
2023-12-20 15:59 ` [tip: timers/core] " tip-bot2 for Anna-Maria Behnsen
2023-12-01 9:26 ` [PATCH v9 07/32] timers: Move store of next event into __next_timer_interrupt() Anna-Maria Behnsen
2023-12-20 15:59 ` [tip: timers/core] " tip-bot2 for Anna-Maria Behnsen
2023-12-01 9:26 ` [PATCH v9 08/32] timers: Clarify check in forward_timer_base() Anna-Maria Behnsen
2023-12-20 15:59 ` [tip: timers/core] " tip-bot2 for Anna-Maria Behnsen
2023-12-01 9:26 ` [PATCH v9 09/32] timers: Split out forward timer base functionality Anna-Maria Behnsen
2023-12-20 15:59 ` [tip: timers/core] " tip-bot2 for Anna-Maria Behnsen
2023-12-01 9:26 ` [PATCH v9 10/32] timers: Use already existing function for forwarding timer base Anna-Maria Behnsen
2023-12-20 15:59 ` [tip: timers/core] " tip-bot2 for Anna-Maria Behnsen
2023-12-01 9:26 ` [PATCH v9 11/32] timers: Rework idle logic Anna-Maria Behnsen
2023-12-20 14:00 ` Frederic Weisbecker
2023-12-20 15:59 ` [tip: timers/core] " tip-bot2 for Thomas Gleixner
2023-12-01 9:26 ` [PATCH v9 12/32] timers: Fix nextevt calculation when no timers are pending Anna-Maria Behnsen
2023-12-04 16:03 ` Sebastian Siewior
2023-12-05 11:53 ` Anna-Maria Behnsen
2023-12-10 0:35 ` Frederic Weisbecker
2023-12-12 13:21 ` Anna-Maria Behnsen
2023-12-12 13:37 ` Frederic Weisbecker
2023-12-20 14:49 ` Frederic Weisbecker
2023-12-20 15:59 ` [tip: timers/core] " tip-bot2 for Anna-Maria Behnsen
2023-12-01 9:26 ` [PATCH v9 13/32] timers: Restructure get_next_timer_interrupt() Anna-Maria Behnsen
2023-12-01 9:26 ` [PATCH v9 14/32] timers: Split out get next timer interrupt Anna-Maria Behnsen
2023-12-01 9:26 ` [PATCH v9 15/32] timers: Move marking timer bases idle into tick_nohz_stop_tick() Anna-Maria Behnsen
2023-12-01 9:26 ` [PATCH v9 16/32] timers: Optimization for timer_base_try_to_set_idle() Anna-Maria Behnsen
2023-12-04 17:52 ` Sebastian Siewior
2023-12-05 12:05 ` Anna-Maria Behnsen
2023-12-01 9:26 ` [PATCH v9 17/32] timers: Introduce add_timer() variants which modify timer flags Anna-Maria Behnsen
2023-12-05 18:28 ` Sebastian Siewior
2023-12-06 9:24 ` Anna-Maria Behnsen
2023-12-01 9:26 ` [PATCH v9 18/32] workqueue: Use global variant for add_timer() Anna-Maria Behnsen
2023-12-01 9:26 ` [PATCH v9 19/32] timers: add_timer_on(): Make sure TIMER_PINNED flag is set Anna-Maria Behnsen
2023-12-05 18:29 ` Sebastian Siewior
2023-12-06 9:57 ` Anna-Maria Behnsen
2023-12-06 10:26 ` Sebastian Siewior
2023-12-06 10:46 ` Anna-Maria Behnsen
2023-12-01 9:26 ` [PATCH v9 20/32] timers: Ease code in run_local_timers() Anna-Maria Behnsen
2023-12-01 9:26 ` [PATCH v9 21/32] timers: Split next timer interrupt logic Anna-Maria Behnsen
2023-12-05 18:29 ` Sebastian Siewior
2023-12-01 9:26 ` [PATCH v9 22/32] timers: Keep the pinned timers separate from the others Anna-Maria Behnsen
2023-12-05 21:11 ` Sebastian Siewior
2023-12-06 10:23 ` Anna-Maria Behnsen
2023-12-01 9:26 ` [PATCH v9 23/32] timers: Retrieve next expiry of pinned/non-pinned timers separately Anna-Maria Behnsen
2023-12-06 9:47 ` Sebastian Siewior
2023-12-07 10:12 ` Anna-Maria Behnsen
2023-12-01 9:26 ` [PATCH v9 24/32] timers: Split out "get next timer interrupt" functionality Anna-Maria Behnsen
2023-12-06 10:20 ` Sebastian Siewior
2023-12-01 9:26 ` [PATCH v9 25/32] timers: Add get next timer interrupt functionality for remote CPUs Anna-Maria Behnsen
2023-12-06 10:44 ` Sebastian Siewior
2023-12-07 10:27 ` Anna-Maria Behnsen
2023-12-01 9:26 ` [PATCH v9 26/32] timers: Restructure internal locking Anna-Maria Behnsen
2023-12-01 9:26 ` [PATCH v9 27/32] timers: Check if timers base is handled already Anna-Maria Behnsen
2023-12-06 10:58 ` Sebastian Siewior
2023-12-01 9:26 ` [PATCH v9 28/32] tick/sched: Split out jiffies update helper function Anna-Maria Behnsen
2023-12-01 9:26 ` [PATCH v9 29/32] timers: Introduce function to check timer base is_idle flag Anna-Maria Behnsen
2023-12-01 9:26 ` [PATCH v9 30/32] timers: Implement the hierarchical pull model Anna-Maria Behnsen
2023-12-06 16:35 ` Sebastian Siewior
2023-12-08 9:01 ` Anna-Maria Behnsen
2023-12-07 18:09 ` Sebastian Siewior
2023-12-08 10:31 ` Anna-Maria Behnsen
2023-12-08 18:18 ` Sebastian Siewior
2023-12-11 18:04 ` Sebastian Siewior
2023-12-12 11:31 ` Anna-Maria Behnsen
2023-12-12 11:43 ` Anna-Maria Behnsen
2023-12-12 15:59 ` Sebastian Siewior
2023-12-12 12:14 ` Sebastian Siewior [this message]
2023-12-12 14:52 ` Anna-Maria Behnsen
2023-12-12 17:08 ` Sebastian Siewior
2023-12-01 9:26 ` [PATCH v9 31/32] timer_migration: Add tracepoints Anna-Maria Behnsen
2023-12-01 9:26 ` [PATCH v9 32/32] timers: Always queue timers on the local CPU Anna-Maria Behnsen
2023-12-07 12:11 ` [PATCH v9 00/32] timers: Move from a push remote at enqueue to a pull at expiry model Anna-Maria Behnsen
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=20231212121404.C2R9VWj1@linutronix.de \
--to=bigeasy@linutronix.de \
--cc=anna-maria@linutronix.de \
--cc=arjan@infradead.org \
--cc=edumazet@google.com \
--cc=frederic@kernel.org \
--cc=gautham.shenoy@amd.com \
--cc=ggherdovich@suse.cz \
--cc=jstultz@google.com \
--cc=kprateek.nayak@amd.com \
--cc=linux-kernel@vger.kernel.org \
--cc=lukasz.luba@arm.com \
--cc=paulmck@kernel.org \
--cc=peterz@infradead.org \
--cc=rafael.j.wysocki@intel.com \
--cc=riel@surriel.com \
--cc=rostedt@goodmis.org \
--cc=srinivas.pandruvada@intel.com \
--cc=tglx@linutronix.de \
/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®