From patchwork Wed Aug 11 05:48:50 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicholas Piggin X-Patchwork-Id: 1515591 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ozlabs.org (client-ip=112.213.38.117; helo=lists.ozlabs.org; envelope-from=skiboot-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org; receiver=) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=YU8yvCPj; dkim-atps=neutral Received: from lists.ozlabs.org (lists.ozlabs.org [112.213.38.117]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4GkzRN2Xjkz9sWS for ; Wed, 11 Aug 2021 15:49:36 +1000 (AEST) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4GkzRN1GTxz3bVs for ; Wed, 11 Aug 2021 15:49:36 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=YU8yvCPj; dkim-atps=neutral X-Original-To: skiboot@lists.ozlabs.org Delivered-To: skiboot@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gmail.com (client-ip=2607:f8b0:4864:20::102e; helo=mail-pj1-x102e.google.com; envelope-from=npiggin@gmail.com; receiver=) Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=YU8yvCPj; dkim-atps=neutral Received: from mail-pj1-x102e.google.com (mail-pj1-x102e.google.com [IPv6:2607:f8b0:4864:20::102e]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 4GkzQt5KJwz30MX for ; Wed, 11 Aug 2021 15:49:10 +1000 (AEST) Received: by mail-pj1-x102e.google.com with SMTP id u21-20020a17090a8915b02901782c36f543so7877492pjn.4 for ; Tue, 10 Aug 2021 22:49:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=pKoy5Mz9AfHtD/3+kLr4guVof+vtXDYhpg779TEfaf0=; b=YU8yvCPjDeHK00fJRY4wP/afLX7a18lScJOpK66nrc4prxtos/gQF2piqtgEtNHsJL gqMayOQcnK0xJUDntwgUJeyAyKAV0mMiS50ljQ+DNlmYz+z6g0xzM/IDmZZiXBNbt+Da GEKgMQv2Pk8k/WgxWKW3PYPjkbedB+dxhAfarVTxomXV1c3HZ815YkLwZwnyknb/GMO6 xQbwzqkjCSII4ZL9s8zvg9AwN3bUdpF1aMRh9tTPDoILkIPifwz330mrBIjVNX702FVW XXlPXVR34bDgwr/xCYbsOWRAiWMwEYy8qRIvqwcnxAQVllMFG/Sm8oNucqvEp//ypzso UZog== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=pKoy5Mz9AfHtD/3+kLr4guVof+vtXDYhpg779TEfaf0=; b=DMGZux/CfNbmfAHYv4WysE9aQnFpHIGMiVQ0bR+Thgy3coFb0I7gzerPemnNkpubTi lPkocnIG5jxZjlTYFI40uneg1MwGEFufX+P3sCzjPfNBv51hGC4Xid3mRPJsRohKgTYA teea1Qs/s8q1XvmvEMxcbSJ1SfyDuNWx02KvzW1+3EFh28FHDFwx/5IdUuO6MSGkYBqW QRWeg/qFcP7SW/qjUzHqwgRPtA6RfD8XuNHEkhQHmgqzNok5Y+iMy0cVie+Xc4c5NiLr IOMosVhGSNu0yiVtDYYhMYMiBIXcGXZzztaZeLiPTKHeY9uD8/XeYOFSAKPCFjJBxTYW dAPg== X-Gm-Message-State: AOAM531TsH+0aD0lTQpt6cPDmPORY0df1Kox3DkBYH2mU+rKXb2JnCE8 1ap/tu9QnFpG9eRis8urB1917/EAY9k= X-Google-Smtp-Source: ABdhPJzWMKOy3Er2iqcbEtNRQRcFhsE6R0Tmi/I1dkz86sY77F4K1l8plua2z5o+gqEwdVzkJzCxLw== X-Received: by 2002:a17:90a:a78d:: with SMTP id f13mr34549117pjq.206.1628660948386; Tue, 10 Aug 2021 22:49:08 -0700 (PDT) Received: from bobo.ibm.com ([118.210.97.79]) by smtp.gmail.com with ESMTPSA id q1sm1222317pjl.44.2021.08.10.22.49.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Aug 2021 22:49:08 -0700 (PDT) From: Nicholas Piggin To: skiboot@lists.ozlabs.org Date: Wed, 11 Aug 2021 15:48:50 +1000 Message-Id: <20210811054851.861482-6-npiggin@gmail.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20210811054851.861482-1-npiggin@gmail.com> References: <20210811054851.861482-1-npiggin@gmail.com> MIME-Version: 1.0 Subject: [Skiboot] [PATCH v1 5/6] core/cpu: make cpu idle states simpler X-BeenThere: skiboot@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Mailing list for skiboot development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: skiboot-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Skiboot" in_idle is true for any kind of idle. This is not used anywhere except for state assertions, but it could be used to remove the idle_lock and global counter if that becomes a significant cost. in_sleep is true for sleep that requires an IPI to wake up. in_job_sleep is true for sleep that wants an IPI sent after a job is queued, and implies in_sleep. Signed-off-by: Nicholas Piggin --- core/cpu.c | 26 +++++++++++++++++++------- include/cpu.h | 3 ++- 2 files changed, 21 insertions(+), 8 deletions(-) diff --git a/core/cpu.c b/core/cpu.c index 0b05d28c6..2cafa4301 100644 --- a/core/cpu.c +++ b/core/cpu.c @@ -104,7 +104,7 @@ static void cpu_wake(struct cpu_thread *cpu) { /* Is it idle ? If not, no need to wake */ sync(); - if (cpu->in_idle) + if (cpu->in_job_sleep) cpu_send_ipi(cpu); } @@ -391,7 +391,8 @@ static unsigned int cpu_idle_p8(enum cpu_wake_cause wake_on) /* Synchronize with wakers */ if (wake_on == cpu_wake_on_job) { /* Mark ourselves in idle so other CPUs know to send an IPI */ - cpu->in_idle = true; + cpu->in_sleep = true; + cpu->in_job_sleep = true; sync(); /* Check for jobs again */ @@ -425,8 +426,8 @@ static unsigned int cpu_idle_p8(enum cpu_wake_cause wake_on) skip_sleep: /* Restore */ sync(); - cpu->in_idle = false; cpu->in_sleep = false; + cpu->in_job_sleep = false; reset_cpu_icp(); return vec; @@ -447,7 +448,8 @@ static unsigned int cpu_idle_p9(enum cpu_wake_cause wake_on) /* Synchronize with wakers */ if (wake_on == cpu_wake_on_job) { /* Mark ourselves in idle so other CPUs know to send an IPI */ - cpu->in_idle = true; + cpu->in_sleep = true; + cpu->in_job_sleep = true; sync(); /* Check for jobs again */ @@ -493,8 +495,8 @@ static unsigned int cpu_idle_p9(enum cpu_wake_cause wake_on) skip_sleep: /* Restore */ sync(); - cpu->in_idle = false; cpu->in_sleep = false; + cpu->in_job_sleep = false; return vec; } @@ -543,10 +545,15 @@ static int nr_cpus_idle = 0; static void enter_idle(void) { + struct cpu_thread *cpu = this_cpu(); + + assert(!cpu->in_idle); + for (;;) { lock(&idle_lock); if (!reconfigure_idle) { nr_cpus_idle++; + cpu->in_idle = true; break; } unlock(&idle_lock); @@ -563,9 +570,14 @@ static void enter_idle(void) static void exit_idle(void) { + struct cpu_thread *cpu = this_cpu(); + + assert(cpu->in_idle); + lock(&idle_lock); assert(nr_cpus_idle > 0); nr_cpus_idle--; + cpu->in_idle = false; unlock(&idle_lock); } @@ -596,12 +608,12 @@ static void reconfigure_idle_start(void) /* * Order earlier store to reconfigure_idle=true vs load from - * cpu->in_sleep and cpu->in_idle. + * cpu->in_sleep. */ sync(); for_each_available_cpu(cpu) { - if (cpu->in_sleep || cpu->in_idle) + if (cpu->in_sleep) cpu_send_ipi(cpu); } diff --git a/include/cpu.h b/include/cpu.h index b0c78ce62..1be5cb0d4 100644 --- a/include/cpu.h +++ b/include/cpu.h @@ -60,8 +60,9 @@ struct cpu_thread { bool in_poller; bool in_reinit; bool in_fast_sleep; - bool in_sleep; bool in_idle; + bool in_sleep; + bool in_job_sleep; uint32_t hbrt_spec_wakeup; /* primary only */ uint64_t save_l2_fir_action1; uint64_t current_token;