Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp272799pxj; Wed, 16 Jun 2021 01:55:27 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzqgx9CLSv6enVLwJtFUGCdx8lQ96QUA6eqF6TyhrzWHH2lN0sF3arT2lvmlqYHEeoddT+f X-Received: by 2002:a17:906:6b8a:: with SMTP id l10mr1821523ejr.125.1623833727453; Wed, 16 Jun 2021 01:55:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1623833727; cv=none; d=google.com; s=arc-20160816; b=slRRx+rVhKn8Ojr2xSE8pWWfuOdei/7sxfWaAP0qs+3vXm+3wLXVdpt+r0CqlR1PoP Wj/hhoTcc1f1QfUmTPs2ypGpRJeaXvAsU+6RBEB9oJHUtBH7FJH6Mvfbq2GdGKqshuFO cYfwCjko6Z1QUtpzCYvMyCTXNHq/qd0rNzQdrizM7fYjW9LYXiNg4pxSE5/MZ/k+p2SY gppQ+a5W13xsB3siEjaHHOtiUma9VAg/yqBqAsq5yOVW1Er/YuZq3yw4SSiqOxvxZOj3 CyHXT8YIXlPpyLBVk9KTT+mlSgrybEZnTWzyhmFSewSiCn66ePYh6gLex7f17bmlqcvI 3Mhg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=2QiwPS2Na/XljEgPdwhB2GK45kJilQMUypk9M8yGWKc=; b=E0RL9QkoN2+iUCI7+WhJgupmJYzwGrpbeXin9JDVsDhn6e6CN0E4vFchFxoGtCK0dY X9i0H7kTJARBSzN7EprV7+OgOi9CwXADBB3CvKeA3sYOm1nC3l56CiBTWg5WQtBgBscp Uk8fH+x3w22FNCbWf81RPT/it+HtyjnvhW9CdUep2udhIZAlxKK0KJOthhBa/bNso+eR q+FDBOFvee5HhdNXhW1XaAQmQrVJ3r7ffx0YKfHeZkPQ8U7ujeBErQsD2JGgzFrI8Waz iY2M23QeXshAL7hETYXkuG3eo6xAfCmPIWGlQtJWgt2tBkNMGYu8bFbJ+U+mMbLFtjRf /drg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=desiato.20200630 header.b=J923zfGL; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id c27si1853255ejj.609.2021.06.16.01.55.05; Wed, 16 Jun 2021 01:55:27 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@infradead.org header.s=desiato.20200630 header.b=J923zfGL; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232208AbhFPIxn (ORCPT + 99 others); Wed, 16 Jun 2021 04:53:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60980 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232195AbhFPIxf (ORCPT ); Wed, 16 Jun 2021 04:53:35 -0400 Received: from desiato.infradead.org (desiato.infradead.org [IPv6:2001:8b0:10b:1:d65d:64ff:fe57:4e05]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9B24FC061760 for ; Wed, 16 Jun 2021 01:51:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=2QiwPS2Na/XljEgPdwhB2GK45kJilQMUypk9M8yGWKc=; b=J923zfGLO3xvSRTXfMYXwWem2o J9U6aDWNCBY5wzx0utXnninp2o6BpfwQzNn5rxdGWwP9fUZMmzbH/Q1esTFabnfmMXhsgP31WLZXA p5Rsd/X62ULqIPNnpaqHuaw8VWF/SDOO4aNcWqunCkm3/J0LYKKKgJvLBcZgkO1Q509qM80R8vgMR pXgUKCoCVKH0UevEPXonP47rUiV/ogofZ+GzQTp/4dc8TyidbEuN8Cx/HORraPk8jsDkE9lkO5Mxw Cq/673aJX5Vde6+Iy5pnZsIYwBhsctP0bOolN/0VJgR/H8jq6McbVRC/qMniZSNsTtGPY6uL3fd2e gojqLUFQ==; Received: from j217100.upc-j.chello.nl ([24.132.217.100] helo=noisy.programming.kicks-ass.net) by desiato.infradead.org with esmtpsa (Exim 4.94.2 #2 (Red Hat Linux)) id 1ltRGV-008H6n-VE; Wed, 16 Jun 2021 08:51:22 +0000 Received: from hirez.programming.kicks-ass.net (hirez.programming.kicks-ass.net [192.168.1.225]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (Client did not present a certificate) by noisy.programming.kicks-ass.net (Postfix) with ESMTPS id A35A2300252; Wed, 16 Jun 2021 10:51:21 +0200 (CEST) Received: by hirez.programming.kicks-ass.net (Postfix, from userid 1000) id 8558E20C169E2; Wed, 16 Jun 2021 10:51:21 +0200 (CEST) Date: Wed, 16 Jun 2021 10:51:21 +0200 From: Peter Zijlstra To: Frederic Weisbecker Cc: Thomas Gleixner , LKML , "Eric W . Biederman" , Oleg Nesterov , Ingo Molnar Subject: Re: [PATCH 2/6] posix-cpu-timers: Don't start process wide cputime counter if timer is disabled Message-ID: References: <20210604113159.26177-1-frederic@kernel.org> <20210604113159.26177-3-frederic@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210604113159.26177-3-frederic@kernel.org> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Jun 04, 2021 at 01:31:55PM +0200, Frederic Weisbecker wrote: > If timer_settime() is called with a 0 expiration on a timer that is > already disabled, the process wide cputime counter will be started > and won't ever get a chance to be stopped by stop_process_timer() since > no timer is actually armed to be processed. > > This process wide counter might bring some performance hit due to the > concurrent atomic additions at the thread group scope. > > The following snippet is enough to trigger the issue. > > void trigger_process_counter(void) > { > timer_t id; > struct itimerspec val = { }; > > timer_create(CLOCK_PROCESS_CPUTIME_ID, NULL, &id); > timer_settime(id, TIMER_ABSTIME, &val, NULL); > timer_delete(id); > } > > So make sure we don't needlessly start it. > > Signed-off-by: Frederic Weisbecker > Cc: Oleg Nesterov > Cc: Thomas Gleixner > Cc: Peter Zijlstra (Intel) > Cc: Ingo Molnar > Cc: Eric W. Biederman > --- > kernel/time/posix-cpu-timers.c | 11 ++++++++--- > 1 file changed, 8 insertions(+), 3 deletions(-) > > diff --git a/kernel/time/posix-cpu-timers.c b/kernel/time/posix-cpu-timers.c > index aa52fc85dbcb..132fd56fb1cd 100644 > --- a/kernel/time/posix-cpu-timers.c > +++ b/kernel/time/posix-cpu-timers.c > @@ -632,10 +632,15 @@ static int posix_cpu_timer_set(struct k_itimer *timer, int timer_flags, > * times (in arm_timer). With an absolute time, we must > * check if it's already passed. In short, we need a sample. > */ > - if (CPUCLOCK_PERTHREAD(timer->it_clock)) > + if (CPUCLOCK_PERTHREAD(timer->it_clock)) { > val = cpu_clock_sample(clkid, p); > - else > - val = cpu_clock_sample_group(clkid, p, true); > + } else { > + /* > + * Sample group but only start the process wide cputime counter > + * if the timer is to be enabled. > + */ > + val = cpu_clock_sample_group(clkid, p, !!new_expires); > + } The cpu_timer_enqueue() is in arm_timer() and the condition for calling that is: 'new_expires != 0 && val < new_expires' Which is not the same as the one you add. I'm thinking the fundamental problem here is the disconnect between cpu_timer_enqueue() and pct->timers_active ?