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 1023EC433EF for ; Sat, 30 Apr 2022 00:00:16 +0000 (UTC) Received: from localhost ([::1] helo=shelob.surriel.com) by shelob.surriel.com with esmtp (Exim 4.94.2) (envelope-from ) id 1nkaWf-0001Xj-Va; Fri, 29 Apr 2022 19:59:53 -0400 Received: from mail-qt1-x832.google.com ([2607:f8b0:4864:20::832]) by shelob.surriel.com with esmtps (TLS1.2) tls TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1nkaWd-0001XX-Vc for kernelnewbies@kernelnewbies.org; Fri, 29 Apr 2022 19:59:52 -0400 Received: by mail-qt1-x832.google.com with SMTP id p4so6371313qtq.12 for ; Fri, 29 Apr 2022 16:59:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=vt-edu.20210112.gappssmtp.com; s=20210112; h=sender:from:to:cc:subject:in-reply-to:references:mime-version:date :message-id; bh=I1z+i0RKtzWnRiOGZai/EpdToes1+8D4XG7pdwsXjv8=; b=Qvj+2MZc5bwx7apgjpVMpa4GMCMDMspJp88IYs9wzZBBIOm51Yj9alAwTYQkKXOeqU 0u7sVftr8awC39KdUmiJ7lhbzAqNvBSVxTKUKjepr4LZUHrpDO7KHELdBIVpIjnT0kuc IGp1AqclBhZtjHg8Q0DuTqRKAnbgTeIANIECdCENDoDaXxaEQ3j8NHOud9NXlOJnlO8k Tq/A5nQkKJzpcETOKgt1i+lXnAU3rHPxZ+plU1+zGBXKXFdH4/Upvv11Jzbdpm+WS2h5 cLOgNRRmDNWWLa1UXoe1g0dAleBZMZQ3OtIb0mS2QxPBRbdsGakmJvnxpU9KeBRmGWYr NvOw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:sender:from:to:cc:subject:in-reply-to:references :mime-version:date:message-id; bh=I1z+i0RKtzWnRiOGZai/EpdToes1+8D4XG7pdwsXjv8=; b=YIY4yo5Nkhd1lDnou8LUuAmuCDr3Nk+/DqC8QDhVWIYff0304lxIbiRdc30DCtJLL6 ehAztN32Ig7yLLhG5tC1dPJOc9L3FQcqPEdcHxcb96OjdDgmRVDc2HvUR6qwnGxxO2Wy kFZkwKxODKZ8ubEK/XbTeW0g1ImzLki+FBU4pKlSf5GZDuegJ9RHrMiLgplItebYNdfL OIjIfmoa0Mbr59sKtoMyF8ARWfMz7NlvbVxN1yjJ/iFijsJQShNWxPnYd2Jgi1WPEMfd U/flNW/8C2hLl7HDKbjI+cIi3xZU7xHmUIf7u20M77lozTE0ub5VzABzlRQ6whEg1YS3 odWw== X-Gm-Message-State: AOAM531Drw633LiAs+AauBcg3TFBHW4ZHZZRFs2/8CsRb+u6+9q2VvR2 X99WSjJjiCM0zk92kLcT2hlzI1PlTxn/pA== X-Google-Smtp-Source: ABdhPJxo5PetDUFbpG94kLC0LKjjhrtYs6RY7DCS/qCGpXO/PZ3rgIaiRLJ9VxWb/koOn49w3Cm7/g== X-Received: by 2002:a05:622a:1b91:b0:2f3:45f0:d9fb with SMTP id bp17-20020a05622a1b9100b002f345f0d9fbmr1754913qtb.147.1651276789544; Fri, 29 Apr 2022 16:59:49 -0700 (PDT) Received: from turing-police ([2601:5c0:c380:d60:f276:1cff:fe8f:1dec]) by smtp.gmail.com with ESMTPSA id v185-20020a372fc2000000b0069fc13ce252sm350237qkh.131.2022.04.29.16.59.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 29 Apr 2022 16:59:48 -0700 (PDT) From: "Valdis Kl=?utf-8?Q?=c4=93?=tnieks" X-Google-Original-From: "Valdis Kl=?utf-8?Q?=c4=93?=tnieks" X-Mailer: exmh version 2.10.0-pre 07/05/2021 with nmh-1.7+dev To: Vincent Ray Subject: Re: smp_processor_id used in preemptable context ? In-reply-to: <1168824437.12549419.1651137327677.JavaMail.zimbra@kalray.eu> References: <1168824437.12549419.1651137327677.JavaMail.zimbra@kalray.eu> Mime-Version: 1.0 Date: Fri, 29 Apr 2022 19:59:47 -0400 Message-ID: <230812.1651276787@turing-police> 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 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