Received: by 2002:ab2:784b:0:b0:1fd:adc2:8405 with SMTP id m11csp484502lqp; Mon, 10 Jun 2024 09:46:29 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVhQQeGQnZxRtBN2+NfBTaCe8zXf+ZEpulPqQT0gMDoUodtTdKePZ0SC1FQTVbXyZ4qceaeYS/7BBXerl/IuYjwoRAZ6DL5yVHoufpHjg== X-Google-Smtp-Source: AGHT+IFVGzY+EqdZEm3keqZK9oub/SJ+IJsQXPG8xqux5w4G6w5guk0LemP9GxfB6en1P/uwfvmg X-Received: by 2002:a05:6a20:7fa0:b0:1ac:c8dc:3e5e with SMTP id adf61e73a8af0-1b2f9a37826mr12465708637.24.1718037989608; Mon, 10 Jun 2024 09:46:29 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1718037989; cv=pass; d=google.com; s=arc-20160816; b=RenDmMMCE/OtvCUp2SuZ8BsTs1oc+IR05iJjeGa92qAQ9jhO+vMAhLcMtgZggITtb3 j/slOQrVVGfoPsL3nzweyar+X2Rz3iJxSDG5tCiT5vPorGdpjrwjDUXpqKWCTNlxMD22 Gh+VX0r4h47zYfWTZ3jKlj67ThmOHvuTVO530u44/5tod7VO75pRPudYg/pWuvEWFdqo ezs1fsdlz6043rVoqjTAGJ7klVNqka8My8w7nU3E0sgZ971aGcJ/OnRZKsfeF+4sPGr7 vxlcBYys1PTbpfWl3j8lOuJzpe2pcBUE9sRb+sL/fwtqVK6Qv/O9EiM5XVNtOwVGGLgD Lwfw== 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=6GMzkiAHRvFkC+fzhDyL20WSpzWzUN7g85C6W+O5hxI=; fh=joBs/8L+orz77ylyCy6wqNwwi35f7sYhLR+/TQjQjhI=; b=GL6dK59KrkGnG2VR9G1ccoevOgbD6ZixmtBmeFeEP+yYdEIb6yEcbXtktAdD7lkFBs AHSj7YHO1kR6w49okB8NSJqko2MAcbthhhw24EXwbPTSiTAngG+Lf+68m1kNnBq8D4o/ WfE5NoBQYdUx89g61aTdv6W1SaaWbcYVLdSjmT4uLEtEXm0LwWOk8wyHVa8UZvylf0Z3 cegdwR6CS9BOrNligmL9/s8trXBVW9neFkkvn/FjQB2gurmm5VI1hRgzHUPtGT+hcfdV HCSe9w7ZNCtQow6vt7VsoGTTvKjDyDVTasfu0GKe7CjnzUmJFPDtV3kjgTRCGpPbAQsa P/6w==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=sw7pA3PX; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=ho83ImrH; 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-208584-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-208584-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id 41be03b00d2f7-6e55b224603si4245003a12.32.2024.06.10.09.46.29 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 10 Jun 2024 09:46:29 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-208584-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=sw7pA3PX; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=ho83ImrH; 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-208584-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-208584-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 sv.mirrors.kernel.org (Postfix) with ESMTPS id 3762228271C for ; Mon, 10 Jun 2024 16:46:29 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id AAD4A15533B; Mon, 10 Jun 2024 16:42:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="sw7pA3PX"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="ho83ImrH" 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 C4B87154BEB for ; Mon, 10 Jun 2024 16:42:31 +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=1718037753; cv=none; b=ryGuFVm/MM63PeKzQJXq8d2MSP3tsn85lE0TYyS6OQ1yTLUf8fPgGFGwBk7F8Fx2OfKm/0eA3QK4x0QFBNBU/6xIO3zuK10ht/1wx1Enmpy6JpS1apXbY2WcfPcDujV4Pe6IH/+YsQP/iA7jSL5wtV1MQ5VdMYWE6BYEIDYWpIw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718037753; c=relaxed/simple; bh=pmCbpSGE0XRK0ukKqo1U6qxPo/JyzQDl0umJpcWyXGY=; h=Message-ID:From:To:Cc:Subject:References:MIME-Version: Content-Type:Date; b=JTUBX0Zg0HduJ6uRr/pW89DMqCQbmiG4Dbwc20mN1n4AEdFf2zzIvMLncyZikizAPUuG5lzIR8JQGnNImPUlHtg634+cGyyu7RoQD3RVzpXjfHJGE//f3PRVxblMiqzq08a5FWWBUm/T4scO8Cwe3L3PgxJYyTjAn0Ud+RaIHWs= 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=sw7pA3PX; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=ho83ImrH; 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: <20240610164026.682500732@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1718037749; 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=6GMzkiAHRvFkC+fzhDyL20WSpzWzUN7g85C6W+O5hxI=; b=sw7pA3PXxHKq7CZr5wAVHO3A03j1R10jIzoElGKiBGmx2kYMOBaWxgdJMLDGlWT4iL34WF QyEKhbgtNs2z7j/FUuTJer8SqTWakAvz+1KPBdt9RQrWZUV3X+9TbonSdqQOChad4FXfMP dkHzDof8kAgd9b9HnRL57YQVrF9BwKWDw5lT1BqRIaO79Hp0CRlYZ4d0MCZ5QJ0t9c6MEg u/06K2jlOAWKTCR3WNa5xODdHl/a+LwCKBjrp+VH98pJMDMH2wij/AO9Rsv9KuKKnaVr5q GoPR0Sr82dzCdCRGQD+IyranA4hma4Kih/zMhr4oAAhtNZ/72KX++zI94W1kQQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1718037749; 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=6GMzkiAHRvFkC+fzhDyL20WSpzWzUN7g85C6W+O5hxI=; b=ho83ImrHdAR2pJ3+KDkZpNjDdUjR22xniGCePaACo6ZBmtY2MsHmYeWB5wyjEpMD5+ZhLI ce6MZyH4SPoUhWDQ== 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 19/51] posix-timers: Convert timer list to hlist 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:28 +0200 (CEST) No requirement for a real list. Spare a few bytes. Signed-off-by: Thomas Gleixner Reviewed-by: Frederic Weisbecker --- fs/proc/base.c | 6 +++--- include/linux/posix-timers.h | 2 +- include/linux/sched/signal.h | 2 +- init/init_task.c | 2 +- kernel/fork.c | 2 +- kernel/time/posix-timers.c | 19 ++++++++----------- 6 files changed, 15 insertions(+), 18 deletions(-) --- a/fs/proc/base.c +++ b/fs/proc/base.c @@ -2456,13 +2456,13 @@ static void *timers_start(struct seq_fil if (!tp->sighand) return ERR_PTR(-ESRCH); - return seq_list_start(&tp->task->signal->posix_timers, *pos); + return seq_hlist_start(&tp->task->signal->posix_timers, *pos); } static void *timers_next(struct seq_file *m, void *v, loff_t *pos) { struct timers_private *tp = m->private; - return seq_list_next(v, &tp->task->signal->posix_timers, pos); + return seq_hlist_next(v, &tp->task->signal->posix_timers, pos); } static void timers_stop(struct seq_file *m, void *v) @@ -2491,7 +2491,7 @@ static int show_timer(struct seq_file *m [SIGEV_THREAD] = "thread", }; - timer = list_entry((struct list_head *)v, struct k_itimer, list); + timer = hlist_entry((struct hlist_node *)v, struct k_itimer, list); notify = timer->it_sigev_notify; seq_printf(m, "ID: %d\n", timer->it_id); --- a/include/linux/posix-timers.h +++ b/include/linux/posix-timers.h @@ -158,7 +158,7 @@ static inline void posix_cputimers_init_ * @rcu: RCU head for freeing the timer. */ struct k_itimer { - struct list_head list; + struct hlist_node list; struct hlist_node t_hash; spinlock_t it_lock; const struct k_clock *kclock; --- a/include/linux/sched/signal.h +++ b/include/linux/sched/signal.h @@ -137,7 +137,7 @@ struct signal_struct { /* POSIX.1b Interval Timers */ unsigned int next_posix_timer_id; - struct list_head posix_timers; + struct hlist_head posix_timers; /* ITIMER_REAL timer for the process */ struct hrtimer real_timer; --- a/init/init_task.c +++ b/init/init_task.c @@ -29,7 +29,7 @@ static struct signal_struct init_signals .cred_guard_mutex = __MUTEX_INITIALIZER(init_signals.cred_guard_mutex), .exec_update_lock = __RWSEM_INITIALIZER(init_signals.exec_update_lock), #ifdef CONFIG_POSIX_TIMERS - .posix_timers = LIST_HEAD_INIT(init_signals.posix_timers), + .posix_timers = HLIST_HEAD_INIT, .cputimer = { .cputime_atomic = INIT_CPUTIME_ATOMIC, }, --- a/kernel/fork.c +++ b/kernel/fork.c @@ -1876,7 +1876,7 @@ static int copy_signal(unsigned long clo prev_cputime_init(&sig->prev_cputime); #ifdef CONFIG_POSIX_TIMERS - INIT_LIST_HEAD(&sig->posix_timers); + INIT_HLIST_HEAD(&sig->posix_timers); hrtimer_init(&sig->real_timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL); sig->real_timer.function = it_real_fn; #endif --- a/kernel/time/posix-timers.c +++ b/kernel/time/posix-timers.c @@ -515,7 +515,7 @@ static int do_timer_create(clockid_t whi spin_lock_irq(¤t->sighand->siglock); /* This makes the timer valid in the hash table */ WRITE_ONCE(new_timer->it_signal, current->signal); - list_add(&new_timer->list, ¤t->signal->posix_timers); + hlist_add_head(&new_timer->list, ¤t->signal->posix_timers); spin_unlock_irq(¤t->sighand->siglock); /* * After unlocking sighand::siglock @new_timer is subject to @@ -1025,7 +1025,7 @@ SYSCALL_DEFINE1(timer_delete, timer_t, t } spin_lock(¤t->sighand->siglock); - list_del(&timer->list); + hlist_del(&timer->list); spin_unlock(¤t->sighand->siglock); /* * A concurrent lookup could check timer::it_signal lockless. It @@ -1075,7 +1075,7 @@ static void itimer_delete(struct k_itime goto retry_delete; } - list_del(&timer->list); + hlist_del(&timer->list); /* * Setting timer::it_signal to NULL is technically not required @@ -1096,22 +1096,19 @@ static void itimer_delete(struct k_itime */ void exit_itimers(struct task_struct *tsk) { - struct list_head timers; - struct k_itimer *tmr; + struct hlist_head timers; - if (list_empty(&tsk->signal->posix_timers)) + if (hlist_empty(&tsk->signal->posix_timers)) return; /* Protect against concurrent read via /proc/$PID/timers */ spin_lock_irq(&tsk->sighand->siglock); - list_replace_init(&tsk->signal->posix_timers, &timers); + hlist_move_list(&tsk->signal->posix_timers, &timers); spin_unlock_irq(&tsk->sighand->siglock); /* The timers are not longer accessible via tsk::signal */ - while (!list_empty(&timers)) { - tmr = list_first_entry(&timers, struct k_itimer, list); - itimer_delete(tmr); - } + while (!hlist_empty(&timers)) + itimer_delete(hlist_entry(timers.first, struct k_itimer, list)); } SYSCALL_DEFINE2(clock_settime, const clockid_t, which_clock,