From: "Valdis Klētnieks" <valdis.kletnieks@vt.edu>
To: Vincent Ray <vray@kalrayinc.com>
Cc: kernelnewbies <kernelnewbies@kernelnewbies.org>
Subject: Re: smp_processor_id used in preemptable context ?
Date: Fri, 29 Apr 2022 19:59:47 -0400 [thread overview]
Message-ID: <230812.1651276787@turing-police> (raw)
In-Reply-To: <1168824437.12549419.1651137327677.JavaMail.zimbra@kalray.eu>
On Thu, 28 Apr 2022 11:15:27 +0200, Vincent Ray said:
> Then I guess it could be preempted at any time, especially with aggressive versions of preemptions ?
> And if so, are we not at risk that our thread is migrated to an other CPU just after smp_processor_id returned ?
Often, we don't actually *care* if it gets migrated. A *lot* of uses of
smp_processor_id() are just to make statistic gathering more efficient.
Rather than all the CPUs do all sorts of locking to avoid race conditions
between different threads updating the same variable, and avoid massive cache
line ping-ponging, the code just gets a pointer to a per_cpu area where we
update some statistic or counter without worrying about that stuff because we
know no other processor should be updating *this* processor's per_cpu area.
Then anything that cares about the *total* across all CPUs can iterate across
all the per_cpu numbers - and that (a) usually happens much less frequently
than updates and (b) only needs to read all the per_cpu area without updating
them.
Yes, there's a very small chance that the "wrong" CPU's stats will be updated. But
let's be realistic - for a lot of statistics, you'll never notice.
_______________________________________________
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
next prev parent reply other threads:[~2022-04-30 0:00 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-04-28 9:15 smp_processor_id used in preemptable context ? Vincent Ray
2022-04-29 23:59 ` Valdis Klētnieks [this message]
2022-04-30 2:27 ` Vincent Ray
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=230812.1651276787@turing-police \
--to=valdis.kletnieks@vt.edu \
--cc=kernelnewbies@kernelnewbies.org \
--cc=vray@kalrayinc.com \
/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