From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from shelob.surriel.com (shelob.surriel.com [96.67.55.147]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id EC66BC433EF for ; Sat, 30 Apr 2022 02:28:12 +0000 (UTC) Received: from localhost ([::1] helo=shelob.surriel.com) by shelob.surriel.com with esmtp (Exim 4.94.2) (envelope-from ) id 1nkcpt-00085L-7M; Fri, 29 Apr 2022 22:27:53 -0400 Received: from smtpout140.security-mail.net ([85.31.212.146] helo=fx601.security-mail.net) by shelob.surriel.com with esmtps (TLS1.2) tls TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1nkcpq-00085B-0z for kernelnewbies@kernelnewbies.org; Fri, 29 Apr 2022 22:27:50 -0400 Received: from localhost (localhost [127.0.0.1]) by fx601.security-mail.net (Postfix) with ESMTP id E2B483ACC27 for ; Sat, 30 Apr 2022 04:27:47 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kalrayinc.com; s=sec-sig-email; t=1651285668; bh=QQX8dBjJQUxUOMwotMHb/7mMBe3TeQ+4u/2c2y14u+E=; h=Date:From:To:Cc:In-Reply-To:References:Subject; b=YW8qFoGjxtaJJqYrceG6GlScEBWS1tuWISSEPFb5aS6ZkjRRH1wfL1JQ0fskkkdX5 V7JkFWzQPRBr0xBad6/rQ6OUr4dVW6ury5n2fsb0ISpnsCl35SzPxLWMD2aqBFxMNC dOY/xEnGUCZLNZOhtWBMztbyfpOloyWItr6lX3XA= Received: from fx601 (localhost [127.0.0.1]) by fx601.security-mail.net (Postfix) with ESMTP id 63D7C3ACC32; Sat, 30 Apr 2022 04:27:47 +0200 (CEST) Received: from zimbra2.kalray.eu (unknown [217.181.231.53]) by fx601.security-mail.net (Postfix) with ESMTPS id 53EC03ACBB1; Sat, 30 Apr 2022 04:27:46 +0200 (CEST) Received: from zimbra2.kalray.eu (localhost [127.0.0.1]) by zimbra2.kalray.eu (Postfix) with ESMTPS id 24B3A27E044F; Sat, 30 Apr 2022 04:27:46 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by zimbra2.kalray.eu (Postfix) with ESMTP id F3FAF27E0456; Sat, 30 Apr 2022 04:27:45 +0200 (CEST) Received: from zimbra2.kalray.eu ([127.0.0.1]) by localhost (zimbra2.kalray.eu [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id p8TErM2pq2hE; Sat, 30 Apr 2022 04:27:45 +0200 (CEST) Received: from zimbra2.kalray.eu (localhost [127.0.0.1]) by zimbra2.kalray.eu (Postfix) with ESMTP id DE18527E044F; Sat, 30 Apr 2022 04:27:45 +0200 (CEST) X-Virus-Scanned: E-securemail, by Secumail Secumail-id: <4b83.626c9ea2.5264f.0> DKIM-Filter: OpenDKIM Filter v2.10.3 zimbra2.kalray.eu F3FAF27E0456 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kalrayinc.com; s=4F334102-7B72-11EB-A74E-42D0B9747555; t=1651285666; bh=/TL0BM7mdsujp9Kb90k7efly6QfLrahcR75VxZ4l0xM=; h=Date:From:To:Message-ID:MIME-Version; b=o8TNj7I5MKzP2BETr5wAJhXbqDJC7vyyu+rcxb4WK6LKwZt0ZpLJY1H7+QAZVVDMH hs5rKQnYFPvff1prJm0d3QSkcVZY+1lcpY7djBV45A2aRm51r976ggoYhwUitrVWZ0 EprbLx9hQEsnXNxBDlcnxvk41Wkl5lfenjxTfaLg/rAkPYAI5uqHaccdFppMrFOsF9 c+7vXHEBn3AnvhxUtHQ/t/DuED3171uPr9WYRYBvSlzJIX9DVCJXO5LFioOFG0HCNF 72uovMh8ekDIrRcahG9w2t4pczOZLevUevsR8FVHJSY4SvCpQ5ZVZ8fGpDKA9AVPPD 4OUZtPSqnsYwA== Date: Sat, 30 Apr 2022 04:27:45 +0200 (CEST) From: Vincent Ray To: Valdis =?utf-8?b?S2zEk3RuaWVrcw==?= Message-ID: <429030342.12743525.1651285665462.JavaMail.zimbra@kalray.eu> In-Reply-To: <230812.1651276787@turing-police> References: <1168824437.12549419.1651137327677.JavaMail.zimbra@kalray.eu> <230812.1651276787@turing-police> Subject: Re: smp_processor_id used in preemptable context ? MIME-Version: 1.0 X-Originating-IP: [192.168.40.202] X-Mailer: Zimbra 9.0.0_GA_4126 (ZimbraWebClient - FF99 (Linux)/9.0.0_GA_4126) Thread-Topic: smp_processor_id used in preemptable context ? Thread-Index: lWuDx+4s8US2TLtPsejpCAnGqTqKwQ== X-ALTERMIMEV2_out: done Cc: kernelnewbies X-BeenThere: kernelnewbies@kernelnewbies.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: Learn about the Linux kernel List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: kernelnewbies-bounces@kernelnewbies.org 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