Re: [PATCH 4/8] shazptr: Avoid synchronize_shaptr() busy waiting
From: Peter Zijlstra
Date: Wed Jun 25 2025 - 07:45:57 EST
On Tue, Jun 24, 2025 at 08:10:57PM -0700, Boqun Feng wrote:
> +/* Scan structure for synchronize_shazptr(). */
> +struct shazptr_scan {
> + /* The scan kthread */
> + struct task_struct *thread;
> +
> + /* Wait queue for the scan kthread */
> + struct swait_queue_head wq;
> +
> + /* Whether the scan kthread has been scheduled to scan */
> + bool scheduled;
> +
> + /* The lock protecting ->queued and ->scheduled */
> + struct mutex lock;
> +
> + /* List of queued synchronize_shazptr() request. */
> + struct list_head queued;
> +
> + int cpu_grp_size;
> +
> + /* List of scanning synchronize_shazptr() request. */
> + struct list_head scanning;
> +
> + /* Buffer used for hazptr slot scan, nr_cpu_ids slots*/
> + struct shazptr_snapshot* snaps;
> +};
I find this style very hard to read, also the order of things is weird.
struct shazptr_scan {
struct task_struct *thread;
struct swait_queue_head wq;
struct list_head scanning;
struct mutex lock;
struct list_head queued; /* __guarded_by(lock) */
bool scheduled; /* __guarded_by(lock) */
struct shazptr_snapshot snaps[0] __counted_by(nr_cpu_ids);
};
(the __guarded_by() thing will come with Thread-Safety support that
Google is still cooking in clang)
> +static struct shazptr_scan shazptr_scan;
And then make this a pointer, and allocate the whole thing as a single
data structure with however much snaps data you need.