Received: by 2002:ab2:784b:0:b0:1fd:adc2:8405 with SMTP id m11csp505199lqp; Mon, 10 Jun 2024 10:20:58 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCX2/fUIDXRF8zncKpRU8ixTridJZUeNUAt3UKZYbVC3ltEJ30c+7dJaTmyNf+um3gtY/QzI/8FBH5pMnxxMnjaIxg1q8Q410hm2nf+iTA== X-Google-Smtp-Source: AGHT+IHQFFW+h4MqMXKMm+LFzmFRnWNG1z7D8JaDVDWxgkO5DuBj4QMWZeudxMrsU8saFNKLGMRn X-Received: by 2002:a05:6358:7242:b0:19f:45a6:4974 with SMTP id e5c5f4694b2df-19f45a65665mr788808055d.6.1718040057976; Mon, 10 Jun 2024 10:20:57 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1718040057; cv=pass; d=google.com; s=arc-20160816; b=QlI2tXh/RLUaAkjTOH6emjVSQ6yCQBMJCo0ThtBKutvLdlCsXfPu+6WNuWLV1huSrb FwY5KjR/Ql2VfvSHxo33Wg/vG+Wi8dhOYg5orti3tuyDpfH9LLaGpsB/0fwYENaNe7YB pCIan8gbFepwtVnwKJ7Repzyy+44AOlESSGN5oPozN9vFnpQKYegCyzo3HoiNUBBQcVJ GuyGv8Ln2noSVEMC+zjgLss7m5yX5X6ajPiowfLhouODa+lV9nCZ/S18cNlBoJbJYLyT dem2WfqZsJkfEr1iKgAMoutvrCEiZc69I+vWLMwImY5xJ+1IjbzETojk5QCJ1ThuS/JT YdBw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=date:mime-version:list-unsubscribe:list-subscribe:list-id :precedence:references:subject:cc:to:from:dkim-signature :dkim-signature:message-id; bh=+/WP0ANjczawtPlZe0Ru3wamTdkxabLE/EGLxYuvFcc=; fh=joBs/8L+orz77ylyCy6wqNwwi35f7sYhLR+/TQjQjhI=; b=HB8GBdN0yDF0fyXLCQbn5mnsamzOuFSrliIJFX6ExHB2hy7OnuswTHjlzYsSonNG38 mDnhA1xzutfntw0auaRw6CilF9YpleEP2Dfjxx4YVHQcI7nkMmVrXyT5L0lfBjw+TRS2 0LT2IA9KrUfpjOpB18igYunFp1fwmnSfs1v4iBy5lC0MODS2SkqlBPoYNM0sc08aMPD2 NNaEQPWjiyg+nBdbJ1rkpf9t81yorWyqc6Qb5zDWmQsr0XssLHRVd8gM5V9b67qHb9SX uM12fJr2heDYqC8Dktbp2bmLWG21HEcuwXJJSkeGXmNGCe5Oarn2XZwc5Tz/wM0ZFfta QAtg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=NwpyE9ZS; dkim=neutral (no key) header.i=@linutronix.de; arc=pass (i=1 spf=pass spfdomain=linutronix.de dkim=pass dkdomain=linutronix.de dmarc=pass fromdomain=linutronix.de); spf=pass (google.com: domain of linux-kernel+bounces-208569-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-208569-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id 41be03b00d2f7-6e7f83b21e3si4411604a12.308.2024.06.10.10.20.57 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 10 Jun 2024 10:20:57 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-208569-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=NwpyE9ZS; dkim=neutral (no key) header.i=@linutronix.de; arc=pass (i=1 spf=pass spfdomain=linutronix.de dkim=pass dkdomain=linutronix.de dmarc=pass fromdomain=linutronix.de); spf=pass (google.com: domain of linux-kernel+bounces-208569-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-208569-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id 262B3B230D0 for ; Mon, 10 Jun 2024 16:43:11 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 60A2114AD3E; Mon, 10 Jun 2024 16:42:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="NwpyE9ZS"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="4Nz0FNd5" Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0497B147C79 for ; Mon, 10 Jun 2024 16:42:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718037740; cv=none; b=LfY4fItyir8yISckXVTFz3EV1HboKHGcMXDFLIyIeed2IgBh1TxSfOduCVlsIYAjFbwlumSCfkc4UIn9rF9LeDv+Jgr7sSUhgx2M+f3B+U61K4JyEGwLasRdQMHOKFVidjpGKdo/BNB1EOJOADDFc80dzqdcibc0GAvmyF4pPAM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718037740; c=relaxed/simple; bh=5E5SF6djGIEJs9V+wAgKePOcQC5ojpZdVLcsv/5ENUo=; h=Message-ID:From:To:Cc:Subject:References:MIME-Version: Content-Type:Date; b=kNpNeL/k+K6KPyNChNgTUypOj9G5LmXHv4iGFVWs13HPidv3dC78XjHBNMkqyTZkMF7RJCSOTE99500pzcgLjqnyE3LN2i8JY72T+hjDseaozW6FvLgutQ4VS2A5aRRuVy5LYYsJUUmqVIWNy9yiot+rO9ypar8qba8P7JO3ZLU= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=NwpyE9ZS; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=4Nz0FNd5; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Message-ID: <20240610164025.906237276@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1718037734; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: references:references; bh=+/WP0ANjczawtPlZe0Ru3wamTdkxabLE/EGLxYuvFcc=; b=NwpyE9ZSbI7SUhvVCW4pjpWpoAPKEG4zEymUB9t6tfyuRF1KDxS5/4IAB+JiTuyAOvelIZ 0oVv4fjWkf/jgb7H2RaAc1NB9c/NFFhwJCPt6hTO9Cae170e+imtVZ6mVXdCbggt6gZ7V7 OA9P5msoUWFDA9YPH1nbe3qJzSFXp7NQ9BPFqX2rAzH37Jg1d08CglEdoJQZW9gqdTlmcw zQRfSA6zRTjymFcObtvNkTEe0P9h3o1P+RQ0iwGXSXGp11rl/O9yQfQozZAJWVu5kjwtAb jz7AAn9PWWtBdYNiu67WjndBkL79d7V4EikFDIJKEw+bZt4EHNs9cWbJWZeY0g== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1718037734; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: references:references; bh=+/WP0ANjczawtPlZe0Ru3wamTdkxabLE/EGLxYuvFcc=; b=4Nz0FNd5QnnxPf9j+V5uVBhIAG0wtvFCbMZDOchf8xsLZIDkRZZXn0tMT6+bEFhP9B+3VG 1GxxZzq4eI3GVWCg== From: Thomas Gleixner To: LKML Cc: Anna-Maria Behnsen , Frederic Weisbecker , John Stultz , Peter Zijlstra , Ingo Molnar , Stephen Boyd , Eric Biederman , Oleg Nesterov Subject: [patch V3 07/51] posix-cpu-timers: Split up posix_cpu_timer_get() References: <20240610163452.591699700@linutronix.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Date: Mon, 10 Jun 2024 18:42:14 +0200 (CEST) In preparation for addressing issues in the timer_get() and timer_set() functions of posix CPU timers. No functional change. Signed-off-by: Thomas Gleixner --- V2: Split out into new patch to make review simpler - Frederic --- kernel/time/posix-cpu-timers.c | 51 +++++++++++++++++++---------------------- 1 file changed, 24 insertions(+), 27 deletions(-) --- a/kernel/time/posix-cpu-timers.c +++ b/kernel/time/posix-cpu-timers.c @@ -785,33 +785,9 @@ static int posix_cpu_timer_set(struct k_ return ret; } -static void posix_cpu_timer_get(struct k_itimer *timer, struct itimerspec64 *itp) +static void __posix_cpu_timer_get(struct k_itimer *timer, struct itimerspec64 *itp, u64 now) { - clockid_t clkid = CPUCLOCK_WHICH(timer->it_clock); - struct cpu_timer *ctmr = &timer->it.cpu; - u64 now, expires = cpu_timer_getexpires(ctmr); - struct task_struct *p; - - rcu_read_lock(); - p = cpu_timer_task_rcu(timer); - if (!p) - goto out; - - /* - * Easy part: convert the reload time. - */ - itp->it_interval = ktime_to_timespec64(timer->it_interval); - - if (!expires) - goto out; - - /* - * Sample the clock to take the difference with the expiry time. - */ - if (CPUCLOCK_PERTHREAD(timer->it_clock)) - now = cpu_clock_sample(clkid, p); - else - now = cpu_clock_sample_group(clkid, p, false); + u64 expires = cpu_timer_getexpires(&timer->it.cpu); if (now < expires) { itp->it_value = ns_to_timespec64(expires - now); @@ -823,7 +799,28 @@ static void posix_cpu_timer_get(struct k itp->it_value.tv_nsec = 1; itp->it_value.tv_sec = 0; } -out: +} + +static void posix_cpu_timer_get(struct k_itimer *timer, struct itimerspec64 *itp) +{ + clockid_t clkid = CPUCLOCK_WHICH(timer->it_clock); + struct task_struct *p; + u64 now; + + rcu_read_lock(); + p = cpu_timer_task_rcu(timer); + if (p) { + itp->it_interval = ktime_to_timespec64(timer->it_interval); + + if (cpu_timer_getexpires(&timer->it.cpu)) { + if (CPUCLOCK_PERTHREAD(timer->it_clock)) + now = cpu_clock_sample(clkid, p); + else + now = cpu_clock_sample_group(clkid, p, false); + + __posix_cpu_timer_get(timer, itp, now); + } + } rcu_read_unlock(); }