Received: by 2002:a05:7412:251c:b0:e2:908c:2ebd with SMTP id w28csp2460046rda; Wed, 25 Oct 2023 03:31:10 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFKlzDb7dc9VnR8tYTbgUz49PSdsUsA8/Q214zb6l+OFszM/BvGQcWZGUzuehCCxX7kFgdo X-Received: by 2002:a5b:b0c:0:b0:d9b:4b94:adf5 with SMTP id z12-20020a5b0b0c000000b00d9b4b94adf5mr14418566ybp.14.1698229870176; Wed, 25 Oct 2023 03:31:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698229870; cv=none; d=google.com; s=arc-20160816; b=PwsbFlswPTqOK6opg+iVf0RsEVvTyM1CLZ8fPr2G9yuH4xf4C1I+qTNkU04kVk8+b6 0qYnff8SVBJPqPR6f8CNUVGf+HjDWv5bh/XfWxdbE/U1YAYnvZ3g2DnXIZUEoe+ScDdE dGmBWosMPAkY2w7NesvgXz71HFEC0abmkCkzPJvCoMmDPj3iqvlMr50hmAY/lN7IaXE7 52FVllkIx/9qo50+jshhIjKRjqFjHxZU4IRFTPeB5iOI0vAOUSM6r94gI+Iq5jR6PZEs NijlvWlYavdXPM+pSkB32Mtr54ipWGhx0B0fwgMow2wGCBmDgfc269p4m7eAnYptfHMr gbcQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=u3vNha6LjEv/b3c8jTWSa/Lwv001Wj+D+Q8nha9WSuA=; fh=FryJ+Cl2P61LIIM/MNyzvWcZ5L0h8ToncgB7RUjeEPw=; b=fFJo+zWGOAXi7GSc4xCyV1TNLZYj3vbFtnRutwoFIVkLszg/+lr/HBVJRsSmOE1pcD 6yKod29FM/RSNvqxIGjUIy09vR9Ld02n+ki85RPe321CT8bI/X4CtAcjEEmHbuW8EuKq qFAPPSRd+UNrfSBRedlObW6k6dMQ9xJsBhA6sbLLY8FDUn0+nqJdL1zzHTA95/O0hnS1 tU/PiA0+2xF7hUG8AwodyQtdWLbbN7f/7S49sLOPRp2HIALMN3CN9YxO3Lnl7rz38DvH 9SdZTAWOWVBFpL5NMO7KCpBTMtL51Z9tSLDVxRsXdhOYxZActbu8u4kfY8X3XgrPLSVF WSYA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=VNIrsB9u; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from howler.vger.email (howler.vger.email. [2620:137:e000::3:4]) by mx.google.com with ESMTPS id o9-20020a257309000000b00d9b33e0b953si10485658ybc.149.2023.10.25.03.31.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 25 Oct 2023 03:31:10 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) client-ip=2620:137:e000::3:4; Authentication-Results: mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=VNIrsB9u; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by howler.vger.email (Postfix) with ESMTP id 2AF2F806AFCF; Wed, 25 Oct 2023 03:31:01 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234693AbjJYKat (ORCPT + 99 others); Wed, 25 Oct 2023 06:30:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34376 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234817AbjJYKam (ORCPT ); Wed, 25 Oct 2023 06:30:42 -0400 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 24BF319D for ; Wed, 25 Oct 2023 03:30:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=u3vNha6LjEv/b3c8jTWSa/Lwv001Wj+D+Q8nha9WSuA=; b=VNIrsB9urY0wekP8UTVIzVjsM2 y6efNVLQ9NwjDhypEthpckjEZPMVeqyEtF/oBg/fgl0pUUWcSvrWLCItoC4101n7brRReLBaGXR2G a61iM8g4J4lzNbWfSVUKJSZiIt0ZetJIH7TCAUv7V19U7lTCyLBziKpv8qio6sSJo6jTy7fQiZZpQ HkZk161Xwc5jYkiD4IhUSJUN+Ao+Bre6qV0ZjA1TtBiDvtJc+utBIyb6NR+WpTRdiV4vCjUR4cjhE zrz0hsVLkrP2y2HedlSlehaycHSosozsQnR+mJeZL5zdcqg+/laDfzXosx8FOj/y0z/0RFfPXElEf H95OXypg==; Received: from j130084.upc-j.chello.nl ([24.132.130.84] helo=noisy.programming.kicks-ass.net) by casper.infradead.org with esmtpsa (Exim 4.94.2 #2 (Red Hat Linux)) id 1qvb96-008CLV-W4; Wed, 25 Oct 2023 10:29:53 +0000 Received: by noisy.programming.kicks-ass.net (Postfix, from userid 1000) id A328730047C; Wed, 25 Oct 2023 12:29:52 +0200 (CEST) Date: Wed, 25 Oct 2023 12:29:52 +0200 From: Peter Zijlstra To: Steven Rostedt Cc: LKML , Thomas Gleixner , Ankur Arora , Linus Torvalds , linux-mm@kvack.org, x86@kernel.org, akpm@linux-foundation.org, luto@kernel.org, bp@alien8.de, dave.hansen@linux.intel.com, hpa@zytor.com, mingo@redhat.com, juri.lelli@redhat.com, vincent.guittot@linaro.org, willy@infradead.org, mgorman@suse.de, jon.grimm@amd.com, bharata@amd.com, raghavendra.kt@amd.com, boris.ostrovsky@oracle.com, konrad.wilk@oracle.com, jgross@suse.com, andrew.cooper3@citrix.com, Joel Fernandes , Youssef Esmat , Vineeth Pillai , Suleiman Souhlal , Ingo Molnar , Daniel Bristot de Oliveira Subject: Re: [POC][RFC][PATCH] sched: Extended Scheduler Time Slice Message-ID: <20231025102952.GG37471@noisy.programming.kicks-ass.net> References: <20231025054219.1acaa3dd@gandalf.local.home> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20231025054219.1acaa3dd@gandalf.local.home> X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on howler.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (howler.vger.email [0.0.0.0]); Wed, 25 Oct 2023 03:31:01 -0700 (PDT) On Wed, Oct 25, 2023 at 05:42:19AM -0400, Steven Rostedt wrote: > That is, there's this structure for every thread. It's assigned with: > > fd = open("/sys/kernel/extend_sched", O_RDWR); > extend_map = mmap(NULL, getpagesize(), PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); > > I don't actually like this interface, as it wastes a full page for just two > bits :-p Perhaps it should be a new system call, where it just locks in > existing memory from the user application? The requirement is that each > thread needs its own bits to play with. It should not be shared with other > threads. It could be, as it will not mess up the kernel, but will mess up > the application. What was wrong with using rseq? > Anyway, to tell the kernel to "extend" the time slice if possible because > it's in a critical section, we have: > > static void extend(void) > { > if (!extend_map) > return; > > extend_map->flags = 1; > } > > And to say that's it's done: > > static void unextend(void) > { > unsigned long prev; > > if (!extend_map) > return; > > prev = xchg(&extend_map->flags, 0); > if (prev & 2) > sched_yield(); > } > > So, bit 1 is for user space to tell the kernel "please extend me", and bit > two is for the kernel to tell user space "OK, I extended you, but call > sched_yield() when done". So what if it doesn't ? Can we kill it for not playing nice ? [ aside from it being bit 0 and bit 1 as you yourself point out, it is also jarring you use a numeral for one and write out the other. ] That said, I properly hate all these things, extending a slice doesn't reliably work and we're always left with people demanding an ever longer extension. The *much* better heuristic is what the kernel uses, don't spin if the lock holder isn't running.