Skip to contentSkip to conversation

RSEQ updates for 6.12

PATCH Superseded Mathieu Desnoyers 3 participants 9 messages Oct 4, 2024 – Oct 9, 2024

Subsystems (6)
VFS Kselftest MM core Scheduler +2 more subsystems

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Mathieu Desnoyers

author maintainer
#0 lore raw

cover RSEQ updates for 6.12

Hi Peter,

This an updated series that contains my rseq updates for 6.12. Sice v0 I've updated the short log of the selftests patch.

It is based on tag v6.12-rc1.

Can you pick it up through the tip tree ?

Thanks,

Mathieu

Cc "Paul E. McKenney" <[email protected]>
Cc Boqun Feng <[email protected]>
Cc Valentin Schneider <[email protected]>
Cc Mel Gorman <[email protected]>
Cc Steven Rostedt <[email protected]>
Cc Vincent Guittot <[email protected]>
Cc Dietmar Eggemann <[email protected]>
Cc Ben Segall <[email protected]>
Cc Yury Norov <[email protected]>
Cc Rasmus Villemoes <[email protected]>

Mathieu Desnoyers (2):
sched: Improve cache locality of RSEQ concurrency IDs for intermittent
workloads
selftests/rseq: Fix mm_cid test failure

 fs/exec.c                           |   2 +-
 include/linux/mm_types.h            |  72 +++++++++++++++---
 kernel/fork.c                       |   2 +-
 kernel/sched/core.c                 |  22 +++---
 kernel/sched/sched.h                |  47 ++++++++----
 tools/testing/selftests/rseq/rseq.c | 109 +++++++++++++++++++---------
 tools/testing/selftests/rseq/rseq.h |  10 +--
 7 files changed, 187 insertions(+), 77 deletions(-)
Signature · 1 line
2.39.2
author maintainer
#1 lore raw

PATCH 1/2 sched: Improve cache locality of RSEQ concurrency IDs for intermittent workloads

commit 223baf9d17f25 ("sched: Fix performance regression introduced by mm_cid") introduced a per-mm/cpu current concurrency id (mm_cid), which keeps a reference to the concurrency id allocated for each CPU. This reference expires shortly after a 100ms delay.

These per-CPU references keep the per-mm-cid data cache-local in situations where threads are running at least once on each CPU within each 100ms window, thus keeping the per-cpu reference alive.

However, intermittent workloads behaving in bursts spaced by more than 100ms on each CPU exhibit bad cache locality and degraded performance compared to purely per-cpu data indexing, because concurrency IDs are allocated over various CPUs and cores, therefore losing cache locality of the associated data.

Introduce the following changes to improve per-mm-cid cache locality:

- Add a "recent_cid" field to the per-mm/cpu mm_cid structure to keep track of which mm_cid value was last used, and use it as a hint to attempt re-allocating the same concurrency ID the next time this mm/cpu needs to allocate a concurrency ID,

- Add a per-mm CPUs allowed mask, which keeps track of the union of CPUs allowed for all threads belonging to this mm. This cpumask is only set during the lifetime of the mm, never cleared, so it represents the union of all the CPUs allowed since the beginning of the mm lifetime. (note that the mm_cpumask() is really arch-specific and tailored to the TLB flush needs, and is thus _not_ a viable approach for this)

- Add a per-mm nr_cpus_allowed to keep track of the weight of the per-mm CPUs allowed mask (for fast access),

- Add a per-mm nr_cids_used to keep track of the highest concurrency ID allocated for the mm. This is used for expanding the concurrency ID allocation within the upper bound defined by:

    min(mm->nr_cpus_allowed, mm->mm_users)

When the next unused CID value reaches this threshold, stop trying to expand the cid allocation and use the first available cid value instead.

Spreading allocation to use all the cid values within the range

[ 0, min(mm->nr_cpus_allowed, mm->mm_users) - 1 ]

improves cache locality while preserving mm_cid compactness within the expected user limits.

- In __mm_cid_try_get, only return cid values within the range [ 0, mm->nr_cpus_allowed ] rather than [ 0, nr_cpu_ids ]. This prevents allocating cids above the number of allowed cpus in rare scenarios where cid allocation races with a concurrent remote-clear of the per-mm/cpu cid. This improvement is made possible by the addition of the per-mm CPUs allowed mask.

- In sched_mm_cid_migrate_to, use mm->nr_cpus_allowed rather than t->nr_cpus_allowed. This criterion was really meant to compare the number of mm->mm_users to the number of CPUs allowed for the entire mm. Therefore, the prior comparison worked fine when all threads shared the same CPUs allowed mask, but not so much in scenarios where those threads have different masks (e.g. each thread pinned to a single CPU). This improvement is made possible by the addition of the per-mm CPUs allowed mask.

* Benchmarks

Each thread increments 16kB worth of 8-bit integers in bursts, with a configurable delay between each thread's execution. Each thread run one after the other (no threads run concurrently). The order of thread execution in the sequence is random. The thread execution sequence begins again after all threads have executed. The 16kB areas are allocated with rseq_mempool and indexed by either cpu_id, mm_cid (not cache-local), or cache-local mm_cid. Each thread is pinned to its own core.

Testing configurations:

8-core/1-L3:        Use 8 cores within a single L3
24-core/24-L3:      Use 24 cores, 1 core per L3
192-core/24-L3:     Use 192 cores (all cores in the system)
384-thread/24-L3:   Use 384 HW threads (all HW threads in the system)

Intermittent workload delays between threads: 200ms, 10ms.

Hardware:

CPU(s):                   384
  On-line CPU(s) list:    0-383
Vendor ID:                AuthenticAMD
  Model name:             AMD EPYC 9654 96-Core Processor
    Thread(s) per core:   2
    Core(s) per socket:   96
    Socket(s):            2
Caches (sum of all):
  L1d:                    6 MiB (192 instances)
  L1i:                    6 MiB (192 instances)
  L2:                     192 MiB (192 instances)
  L3:                     768 MiB (24 instances)

Each result is an average of 5 test runs. The cache-local speedup is calculated as: (cache-local mm_cid) / (mm_cid).

Intermittent workload delay: 200ms

per-cpu mm_cid cache-local mm_cid cache-local speedup
(ns) (ns) (ns)

8-core/1-L3             1374      19289                  1336            14.4x
24-core/24-L3           2423      26721                  1594            16.7x
192-core/24-L3          2291      15826                  2153             7.3x
384-thread/24-L3        1874      13234                  1907             6.9x

Intermittent workload delay: 10ms

per-cpu mm_cid cache-local mm_cid cache-local speedup
(ns) (ns) (ns)

8-core/1-L3               662       756                   686             1.1x
24-core/24-L3            1378      3648                  1035             3.5x
192-core/24-L3           1439     10833                  1482             7.3x
384-thread/24-L3         1503     10570                  1556             6.8x

[ This deprecates the prior "sched: NUMA-aware per-memory-map concurrency IDs"
patch series with a simpler and more general approach. ]

Cc Peter Zijlstra <[email protected]>
Cc Ingo Molnar <[email protected]>
Cc Valentin Schneider <[email protected]>
Cc Mel Gorman <[email protected]>
Cc Steven Rostedt <[email protected]>
Cc Vincent Guittot <[email protected]>
Cc Dietmar Eggemann <[email protected]>
Cc Ben Segall <[email protected]>
Cc Dmitry Vyukov <[email protected]>
Cc Marco Elver <[email protected]>
Cc Yury Norov <[email protected]>
Cc Rasmus Villemoes <[email protected]>
---
 fs/exec.c                |  2 +-
 include/linux/mm_types.h | 72 +++++++++++++++++++++++++++++++++++-----
 kernel/fork.c            |  2 +-
 kernel/sched/core.c      | 22 +++++++-----
 kernel/sched/sched.h     | 47 ++++++++++++++++++--------
 5 files changed, 111 insertions(+), 34 deletions(-)
fs/exec.c +1 -1
index 6c53920795c2..aaa605529a75 100644
@@ -990,7 +990,7 @@ static int exec_mmap(struct mm_struct *mm)
 	active_mm = tsk->active_mm;
 	tsk->active_mm = mm;
 	tsk->mm = mm;
-	mm_init_cid(mm);
+	mm_init_cid(mm, tsk);
 	/*
 	 * This prevents preemption while active_mm is being loaded and
 	 * it and mm are being updated, which could cause problems for
include/linux/mm_types.h +63 -9

126 lines not on this page · raw message

kernel/fork.c +1 -1
index 60c0b4868fd4..18bf37ae73a5 100644
@@ -1298,7 +1298,7 @@ static struct mm_struct *mm_init(struct mm_struct *mm, struct task_struct *p,
 	if (init_new_context(p, mm))
 		goto fail_nocontext;
 
-	if (mm_alloc_cid(mm))
+	if (mm_alloc_cid(mm, p))
 		goto fail_cid;
 
 	if (percpu_counter_init_many(mm->rss_stat, 0, GFP_KERNEL_ACCOUNT,
kernel/sched/core.c +13 -9
index 43e453ab7e20..772a3daf784a 100644
@@ -2691,6 +2691,7 @@ __do_set_cpus_allowed(struct task_struct *p, struct affinity_context *ctx)
 		put_prev_task(rq, p);
 
 	p->sched_class->set_cpus_allowed(p, ctx);
+	mm_set_cpus_allowed(p->mm, ctx->new_mask);
 
 	if (queued)
 		enqueue_task(rq, p, ENQUEUE_RESTORE | ENQUEUE_NOCLOCK);
@@ -10228,6 +10229,7 @@ int __sched_mm_cid_migrate_from_try_steal_cid(struct rq *src_rq,
 	 */
 	if (!try_cmpxchg(&src_pcpu_cid->cid, &lazy_cid, MM_CID_UNSET))
 		return -1;
+	WRITE_ONCE(src_pcpu_cid->recent_cid, MM_CID_UNSET);
 	return src_cid;
 }
 
@@ -10240,7 +10242,8 @@ void sched_mm_cid_migrate_to(struct rq *dst_rq, struct task_struct *t)
 {
 	struct mm_cid *src_pcpu_cid, *dst_pcpu_cid;
 	struct mm_struct *mm = t->mm;
-	int src_cid, dst_cid, src_cpu;
+	int src_cid, src_cpu;
+	bool dst_cid_is_set;
 	struct rq *src_rq;
 
 	lockdep_assert_rq_held(dst_rq);
@@ -10257,9 +10260,9 @@ void sched_mm_cid_migrate_to(struct rq *dst_rq, struct task_struct *t)
 	 * allocation closest to 0 in cases where few threads migrate around
 	 * many CPUs.
 	 *
-	 * If destination cid is already set, we may have to just clear
-	 * the src cid to ensure compactness in frequent migrations
-	 * scenarios.
+	 * If destination cid or recent cid is already set, we may have
+	 * to just clear the src cid to ensure compactness in frequent
+	 * migrations scenarios.
 	 *
 	 * It is not useful to clear the src cid when the number of threads is
 	 * greater or equal to the number of allowed CPUs, because user-space
@@ -10267,9 +10270,9 @@ void sched_mm_cid_migrate_to(struct rq *dst_rq, struct task_struct *t)
 	 * allowed CPUs.
 	 */
 	dst_pcpu_cid = per_cpu_ptr(mm->pcpu_cid, cpu_of(dst_rq));
-	dst_cid = READ_ONCE(dst_pcpu_cid->cid);
-	if (!mm_cid_is_unset(dst_cid) &&
-	    atomic_read(&mm->mm_users) >= t->nr_cpus_allowed)
+	dst_cid_is_set = !mm_cid_is_unset(READ_ONCE(dst_pcpu_cid->cid)) ||
+			 !mm_cid_is_unset(READ_ONCE(dst_pcpu_cid->recent_cid));
+	if (dst_cid_is_set && atomic_read(&mm->mm_users) >= atomic_read(&mm->nr_cpus_allowed))
 		return;
 	src_pcpu_cid = per_cpu_ptr(mm->pcpu_cid, src_cpu);
 	src_rq = cpu_rq(src_cpu);
@@ -10280,13 +10283,14 @@ void sched_mm_cid_migrate_to(struct rq *dst_rq, struct task_struct *t)
 							    src_cid);
 	if (src_cid == -1)
 		return;
-	if (!mm_cid_is_unset(dst_cid)) {
+	if (dst_cid_is_set) {
 		__mm_cid_put(mm, src_cid);
 		return;
 	}
 	/* Move src_cid to dst cpu. */
 	mm_cid_snapshot_time(dst_rq, mm);
 	WRITE_ONCE(dst_pcpu_cid->cid, src_cid);
+	WRITE_ONCE(dst_pcpu_cid->recent_cid, src_cid);
 }
 
 static void sched_mm_cid_remote_clear(struct mm_struct *mm, struct mm_cid *pcpu_cid,
@@ -10523,7 +10527,7 @@ void sched_mm_cid_after_execve(struct task_struct *t)
 		 * Matches barrier in sched_mm_cid_remote_clear_old().
 		 */
 		smp_mb();
-		t->last_mm_cid = t->mm_cid = mm_cid_get(rq, mm);
+		t->last_mm_cid = t->mm_cid = mm_cid_get(rq, t, mm);
 	}
 	rseq_set_notify_resume(t);
 }
kernel/sched/sched.h +33 -14

106 lines not on this page · raw message

Signature · 1 line
2.39.2
maintainer
#2 lore raw

Re: [PATCH v1 1/2] sched: Improve cache locality of RSEQ concurrency IDs for intermittent workloads

Quoted 22 lines · Mathieu Desnoyers

commit 223baf9d17f25 ("sched: Fix performance regression introduced by mm_cid") introduced a per-mm/cpu current concurrency id (mm_cid), which keeps a reference to the concurrency id allocated for each CPU. This reference expires shortly after a 100ms delay.

These per-CPU references keep the per-mm-cid data cache-local in situations where threads are running at least once on each CPU within each 100ms window, thus keeping the per-cpu reference alive.

However, intermittent workloads behaving in bursts spaced by more than 100ms on each CPU exhibit bad cache locality and degraded performance compared to purely per-cpu data indexing, because concurrency IDs are allocated over various CPUs and cores, therefore losing cache locality of the associated data.

Introduce the following changes to improve per-mm-cid cache locality:

- Add a "recent_cid" field to the per-mm/cpu mm_cid structure to keep track of which mm_cid value was last used, and use it as a hint to attempt re-allocating the same concurrency ID the next time this mm/cpu needs to allocate a concurrency ID,

Quoted 7 lines

- Add a per-mm CPUs allowed mask, which keeps track of the union of CPUs allowed for all threads belonging to this mm. This cpumask is only set during the lifetime of the mm, never cleared, so it represents the union of all the CPUs allowed since the beginning of the mm lifetime. (note that the mm_cpumask() is really arch-specific and tailored to the TLB flush needs, and is thus _not_ a viable approach for this)

Because my morning juice came with an excessive dose of pedantry this morning -- the previous and next item end with a comma due to this being an enumeration; but this one has a full stop, suggesting the iteration is at an end.

Quoted 6 lines

- Add a per-mm nr_cpus_allowed to keep track of the weight of the per-mm CPUs allowed mask (for fast access),

- Add a per-mm nr_cids_used to keep track of the highest concurrency ID allocated for the mm. This is used for expanding the concurrency ID allocation within the upper bound defined by:

The description and naming disagree -- while from vague memories they end up being similar -- it is a stumbling block this morning. The description seems to suggest this should be called max_cid or somesuch.

Also, is it actually used for anything? I found the tracking code in __mm_cid_try_get(), but it's not actually doing anything?

Quoted 6 lines
    min(mm->nr_cpus_allowed, mm->mm_users)

When the next unused CID value reaches this threshold, stop trying to expand the cid allocation and use the first available cid value instead.

Quoted 6 lines

Spreading allocation to use all the cid values within the range

[ 0, min(mm->nr_cpus_allowed, mm->mm_users) - 1 ]

improves cache locality while preserving mm_cid compactness within the expected user limits.

This paragraph seems to rudely interrupt the iteration ? Or is (Fred) Colon gone missing again to start a new iteration?

(Damn, and now I need me a Nobby reference somehow)

Anyway, I have vague memories I strongly suggested keeping the CID space dense at some point :-)

Quoted 6 lines

- In __mm_cid_try_get, only return cid values within the range [ 0, mm->nr_cpus_allowed ] rather than [ 0, nr_cpu_ids ]. This prevents allocating cids above the number of allowed cpus in rare scenarios where cid allocation races with a concurrent remote-clear of the per-mm/cpu cid. This improvement is made possible by the addition of the per-mm CPUs allowed mask.

and no comma to continue the iteration.

Quoted 35 lines

- In sched_mm_cid_migrate_to, use mm->nr_cpus_allowed rather than t->nr_cpus_allowed. This criterion was really meant to compare the number of mm->mm_users to the number of CPUs allowed for the entire mm. Therefore, the prior comparison worked fine when all threads shared the same CPUs allowed mask, but not so much in scenarios where those threads have different masks (e.g. each thread pinned to a single CPU). This improvement is made possible by the addition of the per-mm CPUs allowed mask.

include/linux/mm_types.h +10 -0
index 6e3bdf8e38bc..8b5a185b4d5a 100644
@@ -782,6 +782,7 @@ struct vm_area_struct {
 struct mm_cid {
 	u64 time;
 	int cid;
+	int recent_cid;
 };
 #endif
 
@@ -852,6 +853,27 @@ struct mm_struct {
 		 * When the next mm_cid scan is due (in jiffies).
 		 */
 		unsigned long mm_cid_next_scan;
+		/**
+		 * @nr_cpus_allowed: Number of CPUs allowed for mm.
+		 *
+		 * Number of CPUs allowed in the union of all mm's
+		 * threads allowed CPUs.
+		 */
+		atomic_t nr_cpus_allowed;
+		/**
+		 * @nr_cids_used: Number of used concurrency IDs.

include/linux/mm_types.h struct mm_struct { · line 874

Quoted 10 lines
include/linux/mm_types.h +10 -0
+		 *
+		 * Track the highest concurrency ID allocated for the
+		 * mm: nr_cids_used - 1.
+		 */
+		atomic_t nr_cids_used;
+		/**
+		 * @cpus_allowed_lock: Lock protecting mm cpus_allowed.
+		 *
+		 * Provide mutual exclusion for mm cpus_allowed and
+		 * mm nr_cpus_allowed updates.

If nr_cpus_allowed update is serialized by this here thing, why is it an atomic_t? A quick search seems to suggest you're only using atomic_set() / atomic_read() on it, which is a big fat clue it shouldn't be atomic_t.

Am I missing something?

Quoted 41 lines
include/linux/mm_types.h +18 -4
+		 */
+		spinlock_t cpus_allowed_lock;
 #endif
 #ifdef CONFIG_MMU
 		atomic_long_t pgtables_bytes;	/* size of all page tables */
@@ -1170,18 +1192,30 @@ static inline int mm_cid_clear_lazy_put(int cid)
 	return cid & ~MM_CID_LAZY_PUT;
 }
 
+/*
+ * mm_cpus_allowed: Union of all mm's threads allowed CPUs.
+ */
+static inline cpumask_t *mm_cpus_allowed(struct mm_struct *mm)
+{
+	unsigned long bitmap = (unsigned long)mm;
+
+	bitmap += offsetof(struct mm_struct, cpu_bitmap);
+	/* Skip cpu_bitmap */
+	bitmap += cpumask_size();
+	return (struct cpumask *)bitmap;
+}
+
 /* Accessor for struct mm_struct's cidmask. */
 static inline cpumask_t *mm_cidmask(struct mm_struct *mm)
 {
-	unsigned long cid_bitmap = (unsigned long)mm;
+	unsigned long cid_bitmap = (unsigned long)mm_cpus_allowed(mm);
 
-	cid_bitmap += offsetof(struct mm_struct, cpu_bitmap);
-	/* Skip cpu_bitmap */
+	/* Skip mm_cpus_allowed */
 	cid_bitmap += cpumask_size();
 	return (struct cpumask *)cid_bitmap;
 }
 
-static inline void mm_init_cid(struct mm_struct *mm)
+static inline void mm_init_cid(struct mm_struct *mm, struct task_struct *p)
 {
 	int i;
 

include/linux/mm_types.h static inline void mm_init_cid(struct mm_struct *mm) · line 1232

Quoted 10 lines
include/linux/mm_types.h +5 -0
@@ -1189,17 +1223,22 @@ static inline void mm_init_cid(struct mm_struct *mm)
 		struct mm_cid *pcpu_cid = per_cpu_ptr(mm->pcpu_cid, i);
 
 		pcpu_cid->cid = MM_CID_UNSET;
+		pcpu_cid->recent_cid = MM_CID_UNSET;
 		pcpu_cid->time = 0;
 	}
+	atomic_set(&mm->nr_cpus_allowed, p->nr_cpus_allowed);
+	atomic_set(&mm->nr_cids_used, 0);
+	spin_lock_init(&mm->cpus_allowed_lock);
+	cpumask_copy(mm_cpus_allowed(mm), p->cpus_ptr);

Should that not be using p->cpus_mask ? I mean, it is unlikely this code is ran during migrate_disable(), but just in case that ever does do happen, we'll be getting a spurious single CPU mask.

Quoted 23 lines
include/linux/mm_types.h +6 -3
 	cpumask_clear(mm_cidmask(mm));
 }
 
-static inline int mm_alloc_cid_noprof(struct mm_struct *mm)
+static inline int mm_alloc_cid_noprof(struct mm_struct *mm, struct task_struct *p)
 {
 	mm->pcpu_cid = alloc_percpu_noprof(struct mm_cid);
 	if (!mm->pcpu_cid)
 		return -ENOMEM;
-	mm_init_cid(mm);
+	mm_init_cid(mm, p);
 	return 0;
 }
 #define mm_alloc_cid(...)	alloc_hooks(mm_alloc_cid_noprof(__VA_ARGS__))
@@ -1212,16 +1251,31 @@ static inline void mm_destroy_cid(struct mm_struct *mm)
 
 static inline unsigned int mm_cid_size(void)
 {
-	return cpumask_size();
+	return 2 * cpumask_size();	/* mm_cpus_allowed(), mm_cidmask(). */
+}
+
+static inline void mm_set_cpus_allowed(struct mm_struct *mm, const struct cpumask *cpumask)

include/linux/mm_types.h static inline void mm_destroy_cid(struct mm_struct *mm) · line 1267

Quoted 10 lines
include/linux/mm_types.h +10 -0
+{
+	struct cpumask *mm_allowed = mm_cpus_allowed(mm);
+
+	if (!mm)
+		return;
+	/* The mm_cpus_allowed is the union of each thread allowed CPUs masks. */
+	spin_lock(&mm->cpus_allowed_lock);
+	cpumask_or(mm_allowed, mm_allowed, cpumask);
+	atomic_set(&mm->nr_cpus_allowed, cpumask_weight(mm_allowed));
+	spin_unlock(&mm->cpus_allowed_lock);

We're having a problem here, you call this from __do_set_cpus_allowed(), which is holding rq->lock, which is a raw_spinlock_t.

Quoted 22 lines
include/linux/mm_types.h +4 -2
 }
 #else /* CONFIG_SCHED_MM_CID */
-static inline void mm_init_cid(struct mm_struct *mm) { }
-static inline int mm_alloc_cid(struct mm_struct *mm) { return 0; }
+static inline void mm_init_cid(struct mm_struct *mm, struct task_struct *p) { }
+static inline int mm_alloc_cid(struct mm_struct *mm, struct task_struct *p) { return 0; }
 static inline void mm_destroy_cid(struct mm_struct *mm) { }
+
 static inline unsigned int mm_cid_size(void)
 {
 	return 0;
 }
+static inline void mm_set_cpus_allowed(struct mm_struct *mm, const struct cpumask *cpumask) { }
 #endif /* CONFIG_SCHED_MM_CID */
 
 struct mmu_gather;
kernel/sched/core.c +0 -0
index 43e453ab7e20..772a3daf784a 100644

kernel/sched/core.c __do_set_cpus_allowed(struct task_struct *p, struct affinity_context *ctx) · line 2694

Quoted 4 lines
kernel/sched/core.c +1 -0
@@ -2691,6 +2691,7 @@ __do_set_cpus_allowed(struct task_struct *p, struct affinity_context *ctx)
 		put_prev_task(rq, p);
 
 	p->sched_class->set_cpus_allowed(p, ctx);
+	mm_set_cpus_allowed(p->mm, ctx->new_mask);

This here, is with p->pi_lock and rq->lock held -- both are raw_spinlock_t.

Quoted 3 lines
kernel/sched/core.c +0 -0
 	if (queued)
 		enqueue_task(rq, p, ENQUEUE_RESTORE | ENQUEUE_NOCLOCK);
author maintainer
#3 lore raw

Re: [PATCH v1 1/2] sched: Improve cache locality of RSEQ concurrency IDs for intermittent workloads

Quoted 31 lines · Peter Zijlstra
Quoted 22 lines · Mathieu Desnoyers

commit 223baf9d17f25 ("sched: Fix performance regression introduced by mm_cid") introduced a per-mm/cpu current concurrency id (mm_cid), which keeps a reference to the concurrency id allocated for each CPU. This reference expires shortly after a 100ms delay.

These per-CPU references keep the per-mm-cid data cache-local in situations where threads are running at least once on each CPU within each 100ms window, thus keeping the per-cpu reference alive.

However, intermittent workloads behaving in bursts spaced by more than 100ms on each CPU exhibit bad cache locality and degraded performance compared to purely per-cpu data indexing, because concurrency IDs are allocated over various CPUs and cores, therefore losing cache locality of the associated data.

Introduce the following changes to improve per-mm-cid cache locality:

- Add a "recent_cid" field to the per-mm/cpu mm_cid structure to keep track of which mm_cid value was last used, and use it as a hint to attempt re-allocating the same concurrency ID the next time this mm/cpu needs to allocate a concurrency ID,

Quoted 7 lines

- Add a per-mm CPUs allowed mask, which keeps track of the union of CPUs allowed for all threads belonging to this mm. This cpumask is only set during the lifetime of the mm, never cleared, so it represents the union of all the CPUs allowed since the beginning of the mm lifetime. (note that the mm_cpumask() is really arch-specific and tailored to the TLB flush needs, and is thus _not_ a viable approach for this)

Quoted 4 lines

Because my morning juice came with an excessive dose of pedantry this morning -- the previous and next item end with a comma due to this being an enumeration; but this one has a full stop, suggesting the iteration is at an end.

Lol, yes, I'll fix it thanks.

Quoted 11 lines
Quoted 7 lines

- Add a per-mm nr_cpus_allowed to keep track of the weight of the per-mm CPUs allowed mask (for fast access),

- Add a per-mm nr_cids_used to keep track of the highest concurrency ID allocated for the mm. This is used for expanding the concurrency ID allocation within the upper bound defined by:

The description and naming disagree -- while from vague memories they end up being similar -- it is a stumbling block this morning. The description seems to suggest this should be called max_cid or somesuch.

I am tempted to go for max_nr_cid then, so we keep tracking a _number_ of concurrency IDs, because its purpose is to be compared with mm->nr_cpus_allowed and mm->mm_users, which are also counts.

So I should change the way it is used in __mm_cid_try_get() to:

        /*
         * Expand cid allocation if the maximum number of concurrency
         * IDs allocated (max_nr_cid) is below the number cpus allowed
         * and number of threads. Expanding cid allocation as much as
         * possible improves cache locality.
         */
        cid = atomic_read(&mm->max_nr_cid);
        while (cid < atomic_read(&mm->nr_cpus_allowed) && cid < atomic_read(&mm->mm_users)) {
                if (!atomic_try_cmpxchg(&mm->max_nr_cid, &cid, cid + 1))
                        continue;
                if (!cpumask_test_and_set_cpu(cid, cidmask))
                        return cid;
        }
Quoted 3 lines

Also, is it actually used for anything? I found the tracking code in __mm_cid_try_get(), but it's not actually doing anything?

It does something if there is no recent CID to reuse. Then we prefer expanding with new CIDs (rather than find first available) as we are within the range of nr_cpus_allowed and mm_users. Else, we use the first available CID (favor compactness).

Quoted 11 lines
Quoted 11 lines
     min(mm->nr_cpus_allowed, mm->mm_users)

When the next unused CID value reaches this threshold, stop trying to expand the cid allocation and use the first available cid value instead.

Spreading allocation to use all the cid values within the range

   [ 0, min(mm->nr_cpus_allowed, mm->mm_users) - 1 ]
Quoted 7 lines
Quoted 2 lines

improves cache locality while preserving mm_cid compactness within the expected user limits.

This paragraph seems to rudely interrupt the iteration ? Or is (Fred) Colon gone missing again to start a new iteration?

(Damn, and now I need me a Nobby reference somehow)

Lol thanks for the Discworld series good memories :)

Fixed.

Quoted 3 lines

Anyway, I have vague memories I strongly suggested keeping the CID space dense at some point :-)

You did indeed, but benchmarks disagreed up to a certain point with your suggestion. So I've split this in two modes to accommodate each situation:

- When cid allocation is about to go beyond the number of threads in the mm, or beyond the number of allowed cpus, favor compactness and don't go beyond those limits. This provides clear upper bounds for userspace. This follows your earlier strong suggestion to the letter.

- When allocation is within the range limited by the number of threads in the mm and within range of number of allowed cpus, we are free to be compact or not: we've provided no guarantees to userspace there. If we happen to be more compact that those values, this is only due to pure chance and caused by the specific scheduling pattern, thus not something the user should rely on.

And it turns out that for intermittent workloads, there are large gains by making sure we are spreading the cid allocation as much as possible up to that limit rather than keep it compact.

Intermittent workloads can happen if userspace is only scheduled once in a while based on timers, or if the system is overcommitted and thus threads are only scheduled once in a while (each 100+ ms).

Quoted 9 lines
Quoted 7 lines

- In __mm_cid_try_get, only return cid values within the range [ 0, mm->nr_cpus_allowed ] rather than [ 0, nr_cpu_ids ]. This prevents allocating cids above the number of allowed cpus in rare scenarios where cid allocation races with a concurrent remote-clear of the per-mm/cpu cid. This improvement is made possible by the addition of the per-mm CPUs allowed mask.

and no comma to continue the iteration.

Fixed.

Quoted 51 lines
Quoted 36 lines

- In sched_mm_cid_migrate_to, use mm->nr_cpus_allowed rather than t->nr_cpus_allowed. This criterion was really meant to compare the number of mm->mm_users to the number of CPUs allowed for the entire mm. Therefore, the prior comparison worked fine when all threads shared the same CPUs allowed mask, but not so much in scenarios where those threads have different masks (e.g. each thread pinned to a single CPU). This improvement is made possible by the addition of the per-mm CPUs allowed mask.

include/linux/mm_types.h +10 -0
index 6e3bdf8e38bc..8b5a185b4d5a 100644
@@ -782,6 +782,7 @@ struct vm_area_struct {
  struct mm_cid {
  	u64 time;
  	int cid;
+	int recent_cid;
  };
  #endif
 
@@ -852,6 +853,27 @@ struct mm_struct {
  		 * When the next mm_cid scan is due (in jiffies).
  		 */
  		unsigned long mm_cid_next_scan;
+		/**
+		 * @nr_cpus_allowed: Number of CPUs allowed for mm.
+		 *
+		 * Number of CPUs allowed in the union of all mm's
+		 * threads allowed CPUs.
+		 */
+		atomic_t nr_cpus_allowed;
+		/**
+		 * @nr_cids_used: Number of used concurrency IDs.

include/linux/mm_types.h struct mm_struct { · line 874

Quoted 10 lines
include/linux/mm_types.h +10 -0
+		 *
+		 * Track the highest concurrency ID allocated for the
+		 * mm: nr_cids_used - 1.
+		 */
+		atomic_t nr_cids_used;
+		/**
+		 * @cpus_allowed_lock: Lock protecting mm cpus_allowed.
+		 *
+		 * Provide mutual exclusion for mm cpus_allowed and
+		 * mm nr_cpus_allowed updates.

If nr_cpus_allowed update is serialized by this here thing, why is it an atomic_t? A quick search seems to suggest you're only using atomic_set() / atomic_read() on it, which is a big fat clue it shouldn't be atomic_t.

Quoted 1 line

Am I missing something?

Right, I'll use an unsigned int with a READ_ONCE/WRITE_ONCE, because it is read without locking.

Quoted 44 lines
Quoted 44 lines
include/linux/mm_types.h +18 -4
+		 */
+		spinlock_t cpus_allowed_lock;
  #endif
  #ifdef CONFIG_MMU
  		atomic_long_t pgtables_bytes;	/* size of all page tables */
@@ -1170,18 +1192,30 @@ static inline int mm_cid_clear_lazy_put(int cid)
  	return cid & ~MM_CID_LAZY_PUT;
  }
 
+/*
+ * mm_cpus_allowed: Union of all mm's threads allowed CPUs.
+ */
+static inline cpumask_t *mm_cpus_allowed(struct mm_struct *mm)
+{
+	unsigned long bitmap = (unsigned long)mm;
+
+	bitmap += offsetof(struct mm_struct, cpu_bitmap);
+	/* Skip cpu_bitmap */
+	bitmap += cpumask_size();
+	return (struct cpumask *)bitmap;
+}
+
  /* Accessor for struct mm_struct's cidmask. */
  static inline cpumask_t *mm_cidmask(struct mm_struct *mm)
  {
-	unsigned long cid_bitmap = (unsigned long)mm;
+	unsigned long cid_bitmap = (unsigned long)mm_cpus_allowed(mm);
 
-	cid_bitmap += offsetof(struct mm_struct, cpu_bitmap);
-	/* Skip cpu_bitmap */
+	/* Skip mm_cpus_allowed */
  	cid_bitmap += cpumask_size();
  	return (struct cpumask *)cid_bitmap;
  }
 
-static inline void mm_init_cid(struct mm_struct *mm)
+static inline void mm_init_cid(struct mm_struct *mm, struct task_struct *p)
  {
  	int i;
 
@@ -1189,17 +1223,22 @@ static inline void mm_init_cid(struct mm_struct *mm)
  		struct mm_cid *pcpu_cid = per_cpu_ptr(mm->pcpu_cid, i);
 
Quoted 12 lines

include/linux/mm_types.h static inline void mm_init_cid(struct mm_struct *mm) · line 1232

Quoted 8 lines
include/linux/mm_types.h +5 -0
  		pcpu_cid->cid = MM_CID_UNSET;
+		pcpu_cid->recent_cid = MM_CID_UNSET;
  		pcpu_cid->time = 0;
  	}
+	atomic_set(&mm->nr_cpus_allowed, p->nr_cpus_allowed);
+	atomic_set(&mm->nr_cids_used, 0);
+	spin_lock_init(&mm->cpus_allowed_lock);
+	cpumask_copy(mm_cpus_allowed(mm), p->cpus_ptr);

Should that not be using p->cpus_mask ? I mean, it is unlikely this code is ran during migrate_disable(), but just in case that ever does do happen, we'll be getting a spurious single CPU mask.

Good point! Will fix.

Quoted 29 lines
Quoted 29 lines
include/linux/mm_types.h +11 -3
  	cpumask_clear(mm_cidmask(mm));
  }
 
-static inline int mm_alloc_cid_noprof(struct mm_struct *mm)
+static inline int mm_alloc_cid_noprof(struct mm_struct *mm, struct task_struct *p)
  {
  	mm->pcpu_cid = alloc_percpu_noprof(struct mm_cid);
  	if (!mm->pcpu_cid)
  		return -ENOMEM;
-	mm_init_cid(mm);
+	mm_init_cid(mm, p);
  	return 0;
  }
  #define mm_alloc_cid(...)	alloc_hooks(mm_alloc_cid_noprof(__VA_ARGS__))
@@ -1212,16 +1251,31 @@ static inline void mm_destroy_cid(struct mm_struct *mm)
 
  static inline unsigned int mm_cid_size(void)
  {
-	return cpumask_size();
+	return 2 * cpumask_size();	/* mm_cpus_allowed(), mm_cidmask(). */
+}
+
+static inline void mm_set_cpus_allowed(struct mm_struct *mm, const struct cpumask *cpumask)
+{
+	struct cpumask *mm_allowed = mm_cpus_allowed(mm);
+
+	if (!mm)
+		return;
Quoted 8 lines

include/linux/mm_types.h static inline void mm_destroy_cid(struct mm_struct *mm) · line 1267

Quoted 5 lines
include/linux/mm_types.h +5 -0
+	/* The mm_cpus_allowed is the union of each thread allowed CPUs masks. */
+	spin_lock(&mm->cpus_allowed_lock);
+	cpumask_or(mm_allowed, mm_allowed, cpumask);
+	atomic_set(&mm->nr_cpus_allowed, cpumask_weight(mm_allowed));
+	spin_unlock(&mm->cpus_allowed_lock);

We're having a problem here, you call this from __do_set_cpus_allowed(), which is holding rq->lock, which is a raw_spinlock_t.

Good point. It should have been:

                raw_spinlock_t cpus_allowed_lock;

and using raw spin lock/unlock instead.

Quoted 25 lines
Quoted 25 lines
include/linux/mm_types.h +4 -2
  }
  #else /* CONFIG_SCHED_MM_CID */
-static inline void mm_init_cid(struct mm_struct *mm) { }
-static inline int mm_alloc_cid(struct mm_struct *mm) { return 0; }
+static inline void mm_init_cid(struct mm_struct *mm, struct task_struct *p) { }
+static inline int mm_alloc_cid(struct mm_struct *mm, struct task_struct *p) { return 0; }
  static inline void mm_destroy_cid(struct mm_struct *mm) { }
+
  static inline unsigned int mm_cid_size(void)
  {
  	return 0;
  }
+static inline void mm_set_cpus_allowed(struct mm_struct *mm, const struct cpumask *cpumask) { }
  #endif /* CONFIG_SCHED_MM_CID */
 
  struct mmu_gather;
kernel/sched/core.c +0 -0
index 43e453ab7e20..772a3daf784a 100644
@@ -2691,6 +2691,7 @@ __do_set_cpus_allowed(struct task_struct *p, struct affinity_context *ctx)
  		put_prev_task(rq, p);
 
Quoted 5 lines

kernel/sched/core.c __do_set_cpus_allowed(struct task_struct *p, struct affinity_context *ctx) · line 2694

Quoted 2 lines
kernel/sched/core.c +1 -0
  	p->sched_class->set_cpus_allowed(p, ctx);
+	mm_set_cpus_allowed(p->mm, ctx->new_mask);

This here, is with p->pi_lock and rq->lock held -- both are raw_spinlock_t.

Fixing by moving to a raw_spinlock_t.

Thanks!

Mathieu

Quoted 4 lines
Quoted 4 lines
kernel/sched/core.c +0 -0
  	if (queued)
  		enqueue_task(rq, p, ENQUEUE_RESTORE | ENQUEUE_NOCLOCK);
Signature · 3 lines
Mathieu Desnoyers
EfficiOS Inc.
https://www.efficios.com
author maintainer
#4 lore raw

PATCH 2/2 selftests/rseq: Fix mm_cid test failure

In reply to Mathieu Desnoyers

Adapt the rseq.c/rseq.h code to follow GNU C library changes introduced by:

commit 2e456ccf0c34 ("Linux: Make __rseq_size useful for feature detection (bug 31965)")

Without this fix, rseq selftests for mm_cid fail:

./run_param_test.sh
Default parameters
Running test spinlock
Running compare-twice test spinlock
Running mm_cid test spinlock
Error: cpu id getter unavailable

Cc Peter Zijlstra <[email protected]>
CC Boqun Feng <[email protected]>
CC "Paul E. McKenney" <[email protected]>
Cc Shuah Khan <[email protected]>
CC Carlos O'Donell <[email protected]>
CC Florian Weimer <[email protected]>
---
 tools/testing/selftests/rseq/rseq.c | 109 +++++++++++++++++++---------
 tools/testing/selftests/rseq/rseq.h |  10 +--
 2 files changed, 76 insertions(+), 43 deletions(-)
tools/testing/selftests/rseq/rseq.c +74 -35
index 96e812bdf8a4..3797bb0881da 100644
@@ -60,12 +60,6 @@ unsigned int rseq_size = -1U;
 /* Flags used during rseq registration.  */
 unsigned int rseq_flags;
 
-/*
- * rseq feature size supported by the kernel. 0 if the registration was
- * unsuccessful.
- */
-unsigned int rseq_feature_size = -1U;
-
 static int rseq_ownership;
 static int rseq_reg_success;	/* At least one rseq registration has succeded. */
 
@@ -111,6 +105,43 @@ int rseq_available(void)
 	}
 }
 
+/* The rseq areas need to be at least 32 bytes. */
+static
+unsigned get_rseq_min_alloc_size(void)
+{
+	unsigned int alloc_size = rseq_size;
+
+	if (alloc_size < ORIG_RSEQ_ALLOC_SIZE)
+		alloc_size = ORIG_RSEQ_ALLOC_SIZE;
+	return alloc_size;
+}
+
+/*
+ * Return the feature size supported by the kernel.
+ *
+ * Depending on the value returned by getauxval(AT_RSEQ_FEATURE_SIZE):
+ *
+ * 0:   Return ORIG_RSEQ_FEATURE_SIZE (20)
+ * > 0: Return the value from getauxval(AT_RSEQ_FEATURE_SIZE).
+ *
+ * It should never return a value below ORIG_RSEQ_FEATURE_SIZE.
+ */
+static
+unsigned int get_rseq_kernel_feature_size(void)
+{
+	unsigned long auxv_rseq_feature_size, auxv_rseq_align;
+
+	auxv_rseq_align = getauxval(AT_RSEQ_ALIGN);
+	assert(!auxv_rseq_align || auxv_rseq_align <= RSEQ_THREAD_AREA_ALLOC_SIZE);
+
+	auxv_rseq_feature_size = getauxval(AT_RSEQ_FEATURE_SIZE);
+	assert(!auxv_rseq_feature_size || auxv_rseq_feature_size <= RSEQ_THREAD_AREA_ALLOC_SIZE);
+	if (auxv_rseq_feature_size)
+		return auxv_rseq_feature_size;
+	else
+		return ORIG_RSEQ_FEATURE_SIZE;
+}
+
 int rseq_register_current_thread(void)
 {
 	int rc;
@@ -119,7 +150,7 @@ int rseq_register_current_thread(void)
 		/* Treat libc's ownership as a successful registration. */
 		return 0;
 	}
-	rc = sys_rseq(&__rseq_abi, rseq_size, 0, RSEQ_SIG);
+	rc = sys_rseq(&__rseq_abi, get_rseq_min_alloc_size(), 0, RSEQ_SIG);
 	if (rc) {
 		if (RSEQ_READ_ONCE(rseq_reg_success)) {
 			/* Incoherent success/failure within process. */
@@ -140,28 +171,12 @@ int rseq_unregister_current_thread(void)
 		/* Treat libc's ownership as a successful unregistration. */
 		return 0;
 	}
-	rc = sys_rseq(&__rseq_abi, rseq_size, RSEQ_ABI_FLAG_UNREGISTER, RSEQ_SIG);
+	rc = sys_rseq(&__rseq_abi, get_rseq_min_alloc_size(), RSEQ_ABI_FLAG_UNREGISTER, RSEQ_SIG);
 	if (rc)
 		return -1;
 	return 0;
 }
 
-static
-unsigned int get_rseq_feature_size(void)
-{
-	unsigned long auxv_rseq_feature_size, auxv_rseq_align;
-
-	auxv_rseq_align = getauxval(AT_RSEQ_ALIGN);
-	assert(!auxv_rseq_align || auxv_rseq_align <= RSEQ_THREAD_AREA_ALLOC_SIZE);
-
-	auxv_rseq_feature_size = getauxval(AT_RSEQ_FEATURE_SIZE);
-	assert(!auxv_rseq_feature_size || auxv_rseq_feature_size <= RSEQ_THREAD_AREA_ALLOC_SIZE);
-	if (auxv_rseq_feature_size)
-		return auxv_rseq_feature_size;
-	else
-		return ORIG_RSEQ_FEATURE_SIZE;
-}
-
 static __attribute__((constructor))
 void rseq_init(void)
 {
@@ -178,28 +193,53 @@ void rseq_init(void)
 	}
 	if (libc_rseq_size_p && libc_rseq_offset_p && libc_rseq_flags_p &&
 			*libc_rseq_size_p != 0) {
+		unsigned int libc_rseq_size;
+
 		/* rseq registration owned by glibc */
 		rseq_offset = *libc_rseq_offset_p;
-		rseq_size = *libc_rseq_size_p;
+		libc_rseq_size = *libc_rseq_size_p;
 		rseq_flags = *libc_rseq_flags_p;
-		rseq_feature_size = get_rseq_feature_size();
-		if (rseq_feature_size > rseq_size)
-			rseq_feature_size = rseq_size;
+
+		/*
+		 * Previous versions of glibc expose the value
+		 * 32 even though the kernel only supported 20
+		 * bytes initially. Therefore treat 32 as a
+		 * special-case. glibc 2.40 exposes a 20 bytes
+		 * __rseq_size without using getauxval(3) to
+		 * query the supported size, while still allocating a 32
+		 * bytes area. Also treat 20 as a special-case.
+		 *
+		 * Special-cases are handled by using the following
+		 * value as active feature set size:
+		 *
+		 *   rseq_size = min(32, get_rseq_kernel_feature_size())
+		 */
+		switch (libc_rseq_size) {
+		case ORIG_RSEQ_FEATURE_SIZE:	/* Fallthrough. */
+		case ORIG_RSEQ_ALLOC_SIZE:
+		{
+			unsigned int rseq_kernel_feature_size = get_rseq_kernel_feature_size();
+
+			if (rseq_kernel_feature_size < ORIG_RSEQ_ALLOC_SIZE)
+				rseq_size = rseq_kernel_feature_size;
+			else
+				rseq_size = ORIG_RSEQ_ALLOC_SIZE;
+			break;
+		}
+		default:
+			/* Otherwise just use the __rseq_size from libc as rseq_size. */
+			rseq_size = libc_rseq_size;
+			break;
+		}
 		return;
 	}
 	rseq_ownership = 1;
 	if (!rseq_available()) {
 		rseq_size = 0;
-		rseq_feature_size = 0;
 		return;
 	}
 	rseq_offset = (void *)&__rseq_abi - rseq_thread_pointer();
 	rseq_flags = 0;
-	rseq_feature_size = get_rseq_feature_size();
-	if (rseq_feature_size == ORIG_RSEQ_FEATURE_SIZE)
-		rseq_size = ORIG_RSEQ_ALLOC_SIZE;
-	else
-		rseq_size = RSEQ_THREAD_AREA_ALLOC_SIZE;
 }
 
 static __attribute__((destructor))
@@ -209,7 +249,6 @@ void rseq_exit(void)
 		return;
 	rseq_offset = 0;
 	rseq_size = -1U;
-	rseq_feature_size = -1U;
 	rseq_ownership = 0;
 }
 
tools/testing/selftests/rseq/rseq.h +2 -8
index d7364ea4d201..4e217b620e0c 100644
@@ -68,12 +68,6 @@ extern unsigned int rseq_size;
 /* Flags used during rseq registration. */
 extern unsigned int rseq_flags;
 
-/*
- * rseq feature size supported by the kernel. 0 if the registration was
- * unsuccessful.
- */
-extern unsigned int rseq_feature_size;
-
 enum rseq_mo {
 	RSEQ_MO_RELAXED = 0,
 	RSEQ_MO_CONSUME = 1,	/* Unused */
@@ -193,7 +187,7 @@ static inline uint32_t rseq_current_cpu(void)
 
 static inline bool rseq_node_id_available(void)
 {
-	return (int) rseq_feature_size >= rseq_offsetofend(struct rseq_abi, node_id);
+	return (int) rseq_size >= rseq_offsetofend(struct rseq_abi, node_id);
 }
 
 /*
@@ -207,7 +201,7 @@ static inline uint32_t rseq_current_node_id(void)
 
 static inline bool rseq_mm_cid_available(void)
 {
-	return (int) rseq_feature_size >= rseq_offsetofend(struct rseq_abi, mm_cid);
+	return (int) rseq_size >= rseq_offsetofend(struct rseq_abi, mm_cid);
 }
 
 static inline uint32_t rseq_current_mm_cid(void)
Signature · 1 line
2.39.2
maintainer Acked-by on v1 2/2
#5 lore raw

Re: [PATCH v1 2/2] selftests/rseq: Fix mm_cid test failure

Quoted 20 lines · Mathieu Desnoyers

Adapt the rseq.c/rseq.h code to follow GNU C library changes introduced by:

commit 2e456ccf0c34 ("Linux: Make __rseq_size useful for feature detection (bug 31965)")

Without this fix, rseq selftests for mm_cid fail:

./run_param_test.sh
Default parameters
Running test spinlock
Running compare-twice test spinlock
Running mm_cid test spinlock
Error: cpu id getter unavailable

Cc Peter Zijlstra <[email protected]>
CC Boqun Feng <[email protected]>
CC "Paul E. McKenney" <[email protected]>
Cc Shuah Khan <[email protected]>
CC Carlos O'Donell <[email protected]>
CC Florian Weimer <[email protected]>
Quoted 5 lines
---
  tools/testing/selftests/rseq/rseq.c | 109 +++++++++++++++++++---------
  tools/testing/selftests/rseq/rseq.h |  10 +--
  2 files changed, 76 insertions(+), 43 deletions(-)

Looks good to me.

Peter, Ingo - let me know if you plan to take this through one of your trees. Otherwise I will pick it up.

thanks,
-- Shuah

author maintainer
#6 lore raw

Re: [PATCH v1 2/2] selftests/rseq: Fix mm_cid test failure

Quoted 27 lines · Shuah Khan
Quoted 20 lines · Mathieu Desnoyers

Adapt the rseq.c/rseq.h code to follow GNU C library changes introduced by:

commit 2e456ccf0c34 ("Linux: Make __rseq_size useful for feature detection (bug 31965)")

Without this fix, rseq selftests for mm_cid fail:

./run_param_test.sh
Default parameters
Running test spinlock
Running compare-twice test spinlock
Running mm_cid test spinlock
Error: cpu id getter unavailable

Cc Peter Zijlstra <[email protected]>
CC Boqun Feng <[email protected]>
CC "Paul E. McKenney" <[email protected]>
Cc Shuah Khan <[email protected]>
CC Carlos O'Donell <[email protected]>
CC Florian Weimer <[email protected]>
Quoted 5 lines

---
  tools/testing/selftests/rseq/rseq.c | 109 +++++++++++++++++++--------- tools/testing/selftests/rseq/rseq.h |  10 +--

  2 files changed, 76 insertions(+), 43 deletions(-)
Quoted 6 lines

Looks good to me.

Peter, Ingo - let me know if you plan to take this through one of your trees. Otherwise I will pick it up.

Hi Shuah,

I just discussed with Peter on IRC, and if you can pick up this rseq selftest fix through your tree it would be very much appreciated,

Thanks,

Mathieu

Quoted 4 lines

thanks,
-- Shuah

Signature · 3 lines
Mathieu Desnoyers
EfficiOS Inc.
https://www.efficios.com
maintainer
#7 lore raw

Re: [PATCH v1 2/2] selftests/rseq: Fix mm_cid test failure

Quoted 32 lines · Mathieu Desnoyers
Quoted 31 lines · Shuah Khan
Quoted 20 lines · Mathieu Desnoyers

Adapt the rseq.c/rseq.h code to follow GNU C library changes introduced by:

commit 2e456ccf0c34 ("Linux: Make __rseq_size useful for feature detection (bug 31965)")

Without this fix, rseq selftests for mm_cid fail:

./run_param_test.sh
Default parameters
Running test spinlock
Running compare-twice test spinlock
Running mm_cid test spinlock
Error: cpu id getter unavailable

Cc Peter Zijlstra <[email protected]>
CC Boqun Feng <[email protected]>
CC "Paul E. McKenney" <[email protected]>
Cc Shuah Khan <[email protected]>
CC Carlos O'Donell <[email protected]>
CC Florian Weimer <[email protected]>
Quoted 5 lines

---
  tools/testing/selftests/rseq/rseq.c | 109 +++++++++++++++++++--------- tools/testing/selftests/rseq/rseq.h |  10 +--

  2 files changed, 76 insertions(+), 43 deletions(-)

Looks good to me.

Quoted 9 lines
Quoted 2 lines

Peter, Ingo - let me know if you plan to take this through one of your trees. Otherwise I will pick it up.

Hi Shuah,

I just discussed with Peter on IRC, and if you can pick up this rseq selftest fix through your tree it would be very much appreciated,

Thank you for checking. Looks like it doesn't apply to my tree.

2e456ccf0c34 isn't in 6.12 yet?

Also a couple things you could fix. Please cc linux-kselftest when you send the next revision with these fixed.

WARNING: Prefer 'unsigned int' to bare use of 'unsigned' #114: FILE: tools/testing/selftests/rseq/rseq.c:110:
+unsigned get_rseq_min_alloc_size(void)

WARNING: Prefer 'fallthrough;' over fallthrough comment #221: FILE: tools/testing/selftests/rseq/rseq.c:218:
+ case ORIG_RSEQ_FEATURE_SIZE: /* Fallthrough. */

thanks,
-- Shuah

author maintainer
#8 lore raw

Re: [PATCH v1 2/2] selftests/rseq: Fix mm_cid test failure

Quoted 39 lines · Shuah Khan
Quoted 38 lines · Mathieu Desnoyers
Quoted 28 lines · Shuah Khan
Quoted 20 lines · Mathieu Desnoyers

Adapt the rseq.c/rseq.h code to follow GNU C library changes introduced by:

commit 2e456ccf0c34 ("Linux: Make __rseq_size useful for feature detection (bug 31965)")

Without this fix, rseq selftests for mm_cid fail:

./run_param_test.sh
Default parameters
Running test spinlock
Running compare-twice test spinlock
Running mm_cid test spinlock
Error: cpu id getter unavailable

Cc Peter Zijlstra <[email protected]>
CC Boqun Feng <[email protected]>
CC "Paul E. McKenney" <[email protected]>
Cc Shuah Khan <[email protected]>
CC Carlos O'Donell <[email protected]>
CC Florian Weimer <[email protected]>
Quoted 6 lines

---
  tools/testing/selftests/rseq/rseq.c | 109
+++++++++++++++++++---------
  tools/testing/selftests/rseq/rseq.h |  10 +--

  2 files changed, 76 insertions(+), 43 deletions(-)
Quoted 6 lines

Looks good to me.

Peter, Ingo - let me know if you plan to take this through one of your trees. Otherwise I will pick it up.

Hi Shuah,

Quoted 8 lines
Quoted 4 lines

I just discussed with Peter on IRC, and if you can pick up this rseq selftest fix through your tree it would be very much appreciated,

Thank you for checking. Looks like it doesn't apply to my tree.

2e456ccf0c34 isn't in 6.12 yet?

That commit is in the glibc project. I will clarify this in my commit message.

I'll rebase my patch on:

https://git.kernel.org/pub/scm/linux/kernel/git/shuah/linux-kselftest.git
branch: fixes

Quoted 3 lines

Also a couple things you could fix. Please cc linux-kselftest when you send the next revision with these fixed.

OK

Quoted 9 lines

WARNING: Prefer 'unsigned int' to bare use of 'unsigned' #114: FILE: tools/testing/selftests/rseq/rseq.c:110:
+unsigned get_rseq_min_alloc_size(void)

WARNING: Prefer 'fallthrough;' over fallthrough comment #221: FILE: tools/testing/selftests/rseq/rseq.c:218:
+        case ORIG_RSEQ_FEATURE_SIZE:    /* Fallthrough. */

OK

Thanks,

Mathieu

Quoted 3 lines

thanks,
-- Shuah

Signature · 3 lines
Mathieu Desnoyers
EfficiOS Inc.
https://www.efficios.com