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 X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4CF98C48BE8 for ; Fri, 11 Jun 2021 08:30:50 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 3733560FEA for ; Fri, 11 Jun 2021 08:30:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230188AbhFKIcp (ORCPT ); Fri, 11 Jun 2021 04:32:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58956 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231274AbhFKIco (ORCPT ); Fri, 11 Jun 2021 04:32:44 -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 BA7D2C0617AF; Fri, 11 Jun 2021 01:30:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=Content-Type:MIME-Version:References: Subject:Cc:To:From:Date:Message-ID:Sender:Reply-To:Content-Transfer-Encoding: Content-ID:Content-Description:In-Reply-To; bh=fjjwGq8pqbhR8Amjj90Li/rr7dhPD9jU7b7clDXJ1no=; b=AaNNp4ZqkVExFqpWDgpCZBLWCB 6Ok3Q9869i6vMyix6YXtzUjl5O6I66xaJbD6Ubk3Uv5SqzicBYPpQQkf3w5Lzee+t3mwC9A7RiUE9 pEtlp7vFbaYi3DtYOCa7GO5jWdIP2PBKaYHwVleBao8vopZCuUXNQmD2ntbbOt0jsDFOp1bsfX7uf Va+V9NOrQGL/jy24K3EFcUsoZgUPkV/dB2rUXzFiNuNo+cNLqvrMcUteiyFx79MGleimZHgUDGOrF q7X4YP8BVT8NEafJyAtv+z484r0Usn0O0YuiTzHF2GHV7jgxW2FKpRjOZU/dD+akrcxKtDsImubTI meRBVoDw==; 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 1lrcXu-005p87-E6; Fri, 11 Jun 2021 08:29:49 +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 3519830058F; Fri, 11 Jun 2021 10:29:43 +0200 (CEST) Received: by hirez.programming.kicks-ass.net (Postfix, from userid 0) id EC23B2BCF3932; Fri, 11 Jun 2021 10:29:42 +0200 (CEST) Message-ID: <20210611082838.347475156@infradead.org> User-Agent: quilt/0.66 Date: Fri, 11 Jun 2021 10:28:14 +0200 From: Peter Zijlstra To: Thomas Gleixner , Ingo Molnar , Peter Zijlstra , Juri Lelli , Vincent Guittot , Dietmar Eggemann , Steven Rostedt , Ben Segall , Mel Gorman , Daniel Bristot de Oliveira Cc: Borislav Petkov , x86@kernel.org, "H. Peter Anvin" , Jens Axboe , Alasdair Kergon , Mike Snitzer , "David S. Miller" , Jakub Kicinski , Felipe Balbi , Greg Kroah-Hartman , Alexander Viro , Tejun Heo , Zefan Li , Johannes Weiner , Jason Wessel , Daniel Thompson , Douglas Anderson , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , "Rafael J. Wysocki" , Pavel Machek , Will Deacon , Waiman Long , Boqun Feng , Oleg Nesterov , Davidlohr Bueso , "Paul E. McKenney" , Josh Triplett , Mathieu Desnoyers , Lai Jiangshan , Joel Fernandes , John Stultz , Stephen Boyd , Andrew Morton , Paolo Bonzini , Stephen Rothwell , linux-kernel@vger.kernel.org, linux-arch@vger.kernel.org Subject: [PATCH v2 4/7] sched: Add get_current_state() References: <20210611082810.970791107@infradead.org> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Remove yet another few p->state accesses. Signed-off-by: Peter Zijlstra (Intel) Acked-by: Will Deacon --- block/blk-mq.c | 2 +- include/linux/sched.h | 2 ++ kernel/freezer.c | 2 +- kernel/sched/core.c | 6 +++--- 4 files changed, 7 insertions(+), 5 deletions(-) --- a/block/blk-mq.c +++ b/block/blk-mq.c @@ -3891,7 +3891,7 @@ int blk_poll(struct request_queue *q, bl hctx->poll_considered++; - state = current->state; + state = get_current_state(); do { int ret; --- a/include/linux/sched.h +++ b/include/linux/sched.h @@ -212,6 +212,8 @@ struct task_group; #endif +#define get_current_state() READ_ONCE(current->state) + /* Task command name length: */ #define TASK_COMM_LEN 16 --- a/kernel/freezer.c +++ b/kernel/freezer.c @@ -58,7 +58,7 @@ bool __refrigerator(bool check_kthr_stop /* Hmm, should we be allowed to suspend when there are realtime processes around? */ bool was_frozen = false; - long save = current->state; + unsigned int save = get_current_state(); pr_debug("%s entered refrigerator\n", current->comm); --- a/kernel/sched/core.c +++ b/kernel/sched/core.c @@ -8273,15 +8273,15 @@ static inline int preempt_count_equals(i void __might_sleep(const char *file, int line, int preempt_offset) { + unsigned int state = get_current_state(); /* * Blocking primitives will set (and therefore destroy) current->state, * since we will exit with TASK_RUNNING make sure we enter with it, * otherwise we will destroy state. */ - WARN_ONCE(current->state != TASK_RUNNING && current->task_state_change, + WARN_ONCE(state != TASK_RUNNING && current->task_state_change, "do not call blocking ops when !TASK_RUNNING; " - "state=%lx set at [<%p>] %pS\n", - current->state, + "state=%x set at [<%p>] %pS\n", state, (void *)current->task_state_change, (void *)current->task_state_change);