public inbox for kernelnewbies@kernelnewbies.org
 help / color / mirror / Atom feed
From: Vincent Ray <vray@kalrayinc.com>
To: "Valdis Klētnieks" <valdis.kletnieks@vt.edu>
Cc: kernelnewbies <kernelnewbies@kernelnewbies.org>
Subject: Re: smp_processor_id used in preemptable context ?
Date: Sat, 30 Apr 2022 04:27:45 +0200 (CEST)	[thread overview]
Message-ID: <429030342.12743525.1651285665462.JavaMail.zimbra@kalray.eu> (raw)
In-Reply-To: <230812.1651276787@turing-police>

Thanks for your answer Valdis.

So, if I understand well :

1) the comment in net/core/dev.c:__dev_queue_xmit is indeed misleading :

		int cpu = smp_processor_id(); /* ok because BHs are off */

as there is a small chance that we get the wrong info. Disabled BHs are not enough. 
Disabling preemption would be needed to be 100% correct. 
You agree ?

2) You're saying that, most of the time it's ok, as, at worst, we will be a little wrong on some per-cpu stats.
I'm sure it does not matter if cpu0 gets 45 'events' instead of 46, and cpu1 gets 1 extra for free, but that's only if atomic_inc
or something similar is used. If not, can't we end up with completely broken values, with e.g. cpu0 more or less writing its own count, 
totally different from that of cpu1, to cpu1's area ?

3) Finally it looks to me that this particular usage of smp_processor_id() in __dev_queue_xmit() 
is more about preventing a dead loop than just gathering statistics.

Although I don't understand everything going on here, it looks like cpu id is directly used to detect
a bad scenario, leading to a critical message :

	if (dev->flags & IFF_UP) {
		int cpu = smp_processor_id(); /* ok because BHs are off */

		/* Other cpus might concurrently change txq->xmit_lock_owner
		 * to -1 or to their cpu id, but not to our id.
		 */
		if (READ_ONCE(txq->xmit_lock_owner) != cpu) {
[...]
		} else {
			/* Recursion is detected! It is possible,
			 * unfortunately
			 */
recursion_alert:
			net_crit_ratelimited("Dead loop on virtual device %s, fix it urgently!\n",
					     dev->name);

So if our thread is migrated just after smp_processor_id() and lands on the cpu occupied by the thread that is the txq->xmit_lock_owner,
itself just scheduled out, can't we go to the net_crit_ratelimited() ?


Thanks,

V






_______________________________________________
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies

      reply	other threads:[~2022-04-30  2:28 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
2022-04-30  2:27   ` Vincent Ray [this message]

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=429030342.12743525.1651285665462.JavaMail.zimbra@kalray.eu \
    --to=vray@kalrayinc.com \
    --cc=kernelnewbies@kernelnewbies.org \
    --cc=valdis.kletnieks@vt.edu \
    /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