Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp846537pxf; Thu, 18 Mar 2021 13:00:05 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx4KXF74ryDc9osIl5CB394QsIHa/6+02UMMuWjONOTItiBZ+B38aLFaD6ybgb90Plxg66m X-Received: by 2002:aa7:dc04:: with SMTP id b4mr5678717edu.221.1616097605634; Thu, 18 Mar 2021 13:00:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1616097605; cv=none; d=google.com; s=arc-20160816; b=E6Ex+zRg++Lxkw0Ls3fogDEO7LlYff4w1W/DE63I/LMCI2U3G8V6wGKlJQ6txn3r+e L8lKXcfJEnG5ZIutXUvbPsh+7cAFGbz2qg/oFvQzRODuRi+7S3V3Cx8BpzTEEHysKn/f B7Oqa1KA1xapXTdFQBIZ1cYe6CM0UjQKHJ3BHh2WlIb1a9T+fSvJJgkpTtzaap4CkHyz pWqUY3XHJfawYegBaaYgXD+RXVK7KyAu6Tq7sRsaI8ys4+29ElsjiPL/vMA7SsjzGoyU 2ao5LH2KGu046iT5GRhv6vb2Tpq5AhBNVIKfpDsDZFQPZ0QxKKlIv9VtdbZNiMIo/7Wk /z4A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:mime-version:message-id:date :dkim-signature; bh=rtKaq18TsAxjH4hNsZHEOk9XNEGOj6GRidAJBUycwvk=; b=iMluQhlrkAb/cUwvU2TiNk6cqiWh+xUiUT2xeu+GCQOG+kzzSdL4ge6jQPRet95qs/ 5Ysh9GfwDbFVDmA0CNU37ZGkWA0emc4swi+l3eGMdXk7CpRJB3/56Xu18ZcuA6aTudJA o771u1ntIBizHaUTDuFGZ++vTDHTTWyAx6IaZ4ZcHvrfK6PULyocfPSgbNWLk2BU3mmt v5/AtZvXcjWtM/85rj/v40bxMv1NAhqgKEo0xlD1FLL6CkyAtP/HVhDQHANS3MS+14Nl T8WPl+jn8s/LX2g6j1DBK5ejpmF8M7tvTB2pVKcq8AffEg+iWYsSZyZko5tCPbnD3lon bM2w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=QDybR7Ly; 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; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id cf5si2340288ejb.346.2021.03.18.12.59.42; Thu, 18 Mar 2021 13:00:05 -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=@google.com header.s=20161025 header.b=QDybR7Ly; 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; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232924AbhCRT6M (ORCPT + 99 others); Thu, 18 Mar 2021 15:58:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41790 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229958AbhCRT5s (ORCPT ); Thu, 18 Mar 2021 15:57:48 -0400 Received: from mail-qv1-xf49.google.com (mail-qv1-xf49.google.com [IPv6:2607:f8b0:4864:20::f49]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E28CEC06174A for ; Thu, 18 Mar 2021 12:57:47 -0700 (PDT) Received: by mail-qv1-xf49.google.com with SMTP id t18so30560061qva.6 for ; Thu, 18 Mar 2021 12:57:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:message-id:mime-version:subject:from:to:cc; bh=rtKaq18TsAxjH4hNsZHEOk9XNEGOj6GRidAJBUycwvk=; b=QDybR7Ly9v0iT8XsOcDMUneD+yf6WOEmGi25IYk3rX4Y1XWKW1iEv5dFwyaEnciGSL T3Hbm7PfuoCCj2vdtxaT9bIVKu+8k+AgWwLNwaXIVZIrySsoeaxyAIEXkYlq6hbIRACH 9o/kM9jnpwK51vz6XSnihOm6FF8/C82jLGpI3K0JQGjuuRGBnyshRoNm3UOltedz51WU dKzoHHJfJCbB6gFzLFGy4ahvbbP7LBZUiTmYftNq3Ac95iL7AZHXhQvz9i5AFiGtHbFt hfnaSdN+4JetFscFKrH25lto0DdSQsc6v4ji2/TxWNnAXPtFsgZdKOcsg0xFDZ1gvmVg ytuw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:message-id:mime-version:subject:from:to:cc; bh=rtKaq18TsAxjH4hNsZHEOk9XNEGOj6GRidAJBUycwvk=; b=ckhqwDxKTuuHPQV3DiKBYXa7Jtg7Ng2fviB//5FCgV0r/WOT/+vt2p2F5tm4C1XrCT ujdUavujK/qb/IRW8Wc2ar2MsgHqgQnlZJavk8+HAA0WpPvmXCGPTPegBmXMiDIMj3pQ sJx/NidW4XTR108P36Fgv+VvnWFUUnp0UCBgbidonOlDO1oHUaOimur8rZxkivcFmC43 R526NvW41UYVc4P2CgmM9Gl4Ys0t1TqbnNok88N+KRhQV81qMkHC+7wfcG7If0QFbkQx 7Mm6ulxLGIsEI3vzaRz5uQQHIsGevVxpUvQmFzrw7EvIuk6QqFBejdl7pnWvYOEhsq0V EacQ== X-Gm-Message-State: AOAM532EdDJVFj7i2tWQMeiWzA3Fa9+whiA+Nz/MMSa3w1fr0lxmQSqN SO2DJd3BvPEx+Eh2xOZuHmWqqDGS X-Received: from gnomeregan.cam.corp.google.com ([2620:15c:6:412:5dfa:c029:17ab:8f38]) (user=brho job=sendgmr) by 2002:ad4:51c1:: with SMTP id p1mr6158244qvq.39.1616097467014; Thu, 18 Mar 2021 12:57:47 -0700 (PDT) Date: Thu, 18 Mar 2021 15:57:34 -0400 Message-Id: <20210318195734.3579799-1-brho@google.com> Mime-Version: 1.0 X-Mailer: git-send-email 2.31.0.rc2.261.g7f71774620-goog Subject: sched: allow resubmits to queue_balance_callback() From: Barret Rhoden To: Ingo Molnar , Peter Zijlstra , Juri Lelli , Vincent Guittot Cc: Dietmar Eggemann , Steven Rostedt , Ben Segall , Mel Gorman , Daniel Bristot de Oliveira , linux-kernel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Prior to this commit, if you submitted the same callback_head twice, it would be enqueued twice, but only if it was the last callback on the list. The first time it was submitted, rq->balance_callback was NULL, so head->next is NULL. That defeated the check in queue_balance_callback(). This commit changes the callback list such that whenever an item is on the list, its head->next is not NULL. The last element (first inserted) will point to itself. This allows us to detect and ignore any attempt to reenqueue a callback_head. Signed-off-by: Barret Rhoden --- i might be missing something here, but this was my interpretation of what the "if (unlikely(head->next))" check was for in queue_balance_callback. kernel/sched/core.c | 3 ++- kernel/sched/sched.h | 6 +++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/kernel/sched/core.c b/kernel/sched/core.c index 2d95dc3f4644..6322975032ea 100644 --- a/kernel/sched/core.c +++ b/kernel/sched/core.c @@ -3669,7 +3669,8 @@ static void __balance_callback(struct rq *rq) rq->balance_callback = NULL; while (head) { func = (void (*)(struct rq *))head->func; - next = head->next; + /* The last element pointed to itself */ + next = head->next == head ? NULL : head->next; head->next = NULL; head = next; diff --git a/kernel/sched/sched.h b/kernel/sched/sched.h index 28709f6b0975..42629e153f83 100644 --- a/kernel/sched/sched.h +++ b/kernel/sched/sched.h @@ -1389,11 +1389,15 @@ queue_balance_callback(struct rq *rq, { lockdep_assert_held(&rq->lock); + /* + * The last element on the list points to itself, so we can always + * detect if head is already enqueued. + */ if (unlikely(head->next)) return; head->func = (void (*)(struct callback_head *))func; - head->next = rq->balance_callback; + head->next = rq->balance_callback ?: NULL; rq->balance_callback = head; } -- 2.31.0.rc2.261.g7f71774620-goog