From patchwork Tue Jun 6 14:37:31 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Gleixner X-Patchwork-Id: 103887 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp3451481vqr; Tue, 6 Jun 2023 07:51:51 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4VP85Z8LcdX8yceKrGetQN6Bb/u1KD1+9M4UR4qLGniliKonHdp9cXnnhSiMUq8+uZ4G0e X-Received: by 2002:ac8:5ac3:0:b0:3f9:b870:ba13 with SMTP id d3-20020ac85ac3000000b003f9b870ba13mr302131qtd.24.1686063110719; Tue, 06 Jun 2023 07:51:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686063110; cv=none; d=google.com; s=arc-20160816; b=VdlWood2pUqOHS8eKxD68c7+dt+dtNb7PFi5/Cgkx1S+l3RtkPbKWkjM6yZ8qblpM6 93SmyGCDubEcnW5rrEaU+Bh8RQ4Qee+EtERGWDcOc/0NooiuhU5d+Sp0jc863IJN0C5B IRrpoQ8gd+1Rhe1y7dGPAte2CbMuCiUDFOYSoxG3ddaQGrjQrRFjPgPztWI1mc/DP5lF VapJF77TwsIzHOrzgKku3Lt1pFLpQWRVRm34kF8klOqp+cpmEOC851RVXuMQHk+HEGoT C8XwZJCbKW6Iz7XPVX05Iwbo++LtqEUQ69P1VEoferPxE3KMBLwKBTTUcpspCA8G390p H1CA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:date:mime-version:references:subject:cc:to:from :dkim-signature:dkim-signature:message-id; bh=feQqbMJR8LNStx4hiDUEIHYcUpveV5I+mK7qWj22Q+I=; b=h4sJR3ziBZsOVsfKVxqJ4pb8SGNWvsVs7vSwbSx+UdVUqUZJppBILfC6tcKZQ0tlEd keqjC4qn89dep2f+iVwNXIgrTWaK7/a1LUgZn3SjhXZqdv7U1ZxL9PRTaFWI4754GIWt OXpbsgJEkDpxgNJAwgIIx04oxAbRyw87JdqsiPrmlf5KzPd2OoE/oyaZxm3NOEMTHVDV dsyX+RzgyDT4xP8aPQ8BJPHtK0L2pFIvM8xazanZEpniWttv9+vvvG/GZ/sEm0oY57QL LaGLJec9r4QDjvR0ljI9c3jtaNRU92p1Bv4AOytR7nRBRnFnCMQlzNnX2Ie2uExrlX+d ECHg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=K+0PvOJH; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id b4-20020ac85bc4000000b003d53cbf0ecbsi4101820qtb.413.2023.06.06.07.51.35; Tue, 06 Jun 2023 07:51:50 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=K+0PvOJH; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238058AbjFFOh7 (ORCPT + 99 others); Tue, 6 Jun 2023 10:37:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41582 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238014AbjFFOhl (ORCPT ); Tue, 6 Jun 2023 10:37:41 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4DB3710FB for ; Tue, 6 Jun 2023 07:37:33 -0700 (PDT) Message-ID: <20230606142031.475141256@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1686062251; 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=feQqbMJR8LNStx4hiDUEIHYcUpveV5I+mK7qWj22Q+I=; b=K+0PvOJHghqEuSL/XjZ+ievKQ/BpS5nPc98SPu4u7Piv031DQHuSw9oGajptxP1/O3ogEw Fl8h62mYfWJzhBl5vt1SfnvfDv6IZsSKv2SkCdnWniZbRcMcW24rreNAvg5IFmYuJPH25V 8/A8aPCo2v2h6c+XDhMrLrBrRY9PaCT0+uUpc4KREfVFN7t97aDXY5hWuqtYp6/LUg/gdU FD5gLMYyWUjwLccJ3W1YoL64EQ0KSi+4O9ewaCKY/+VUesGZWbzBVVhb0bN/KHpZ17NiK1 19EOg+RuOZcA4sR2BL32JucxrtRvxhIoNTYZ2saEXqn0+S6yjn3mqpv1K1J98w== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1686062251; 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=feQqbMJR8LNStx4hiDUEIHYcUpveV5I+mK7qWj22Q+I=; b=t67079sbUXtqL232iy/n95/NpVWYpidkqzaBa5qDnHjwomga0pshXT7Z0jzaT88DiOzQz+ gBhkOKIZPUOtoeAw== From: Thomas Gleixner To: LKML Cc: Frederic Weisbecker , Anna-Maria Behnsen , John Stultz , Peter Zijlstra , Ingo Molnar , Stephen Boyd , Eric Biederman , Oleg Nesterov Subject: [patch 08/45] posix-timers: Convert timer list to hlist References: <20230606132949.068951363@linutronix.de> MIME-Version: 1.0 Date: Tue, 6 Jun 2023 16:37:31 +0200 (CEST) X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1767965312434158290?= X-GMAIL-MSGID: =?utf-8?q?1767965312434158290?= 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 | 16 ++++++++-------- 6 files changed, 15 insertions(+), 15 deletions(-) --- a/fs/proc/base.c +++ b/fs/proc/base.c @@ -2461,13 +2461,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) @@ -2496,7 +2496,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 @@ -221,7 +221,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 @@ -136,7 +136,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 @@ -28,7 +28,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 @@ -1880,7 +1880,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 @@ -1021,7 +1021,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 @@ -1071,7 +1071,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 @@ -1092,20 +1092,20 @@ static void itimer_delete(struct k_itime */ void exit_itimers(struct task_struct *tsk) { - struct list_head timers; + struct hlist_head timers; struct k_itimer *tmr; - 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); + while (!hlist_empty(&timers)) { + tmr = hlist_entry(timers.first, struct k_itimer, list); itimer_delete(tmr); } }