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 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4B03DC25B47 for ; Wed, 25 Oct 2023 10:30:27 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C01C68D0007; Wed, 25 Oct 2023 06:30:26 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id BB1CD8D0001; Wed, 25 Oct 2023 06:30:26 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id AA0978D0007; Wed, 25 Oct 2023 06:30:26 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 9B05E8D0001 for ; Wed, 25 Oct 2023 06:30:26 -0400 (EDT) Received: from smtpin14.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 6B98BC07D3 for ; Wed, 25 Oct 2023 10:30:26 +0000 (UTC) X-FDA: 81383614452.14.0D7D810 Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf12.hostedemail.com (Postfix) with ESMTP id A93234001C for ; Wed, 25 Oct 2023 10:30:23 +0000 (UTC) Authentication-Results: imf12.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=VNIrsB9u; dmarc=none; spf=none (imf12.hostedemail.com: domain of peterz@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=peterz@infradead.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1698229823; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=u3vNha6LjEv/b3c8jTWSa/Lwv001Wj+D+Q8nha9WSuA=; b=WJVBUjN6n1KNRGKGfIOVdzc/0XmRdksUDGpEyR1woxOWN5BHHJ34RDyX26fk7vWbXBgs8l +j2chwyO77VdPOrmkN2JFzFeWojpdi+oeXmiO5K2lzlDoe+VyQqQCS9QbwXAmYiV2WjkUp cAODPbyC7eJe+JtRfpLnO6oMmc17NF0= ARC-Authentication-Results: i=1; imf12.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=VNIrsB9u; dmarc=none; spf=none (imf12.hostedemail.com: domain of peterz@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=peterz@infradead.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1698229823; a=rsa-sha256; cv=none; b=hbOH9jirOiBBe7s0NRB6snTVLkKrFZGFGGXk6nhpoiBOtMWvOgcfizfJY2T1Lp6sQGcrwN Bg4jbMOKwPgsUZdaOcTsayIwy7keinCdSz48aXPhSBjv4FDvpsWPVd4x4S3nM5AbDkYjih 8ajuki/Jwn4sNEyZuoP2J/GcVUF44G0= 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-Rspamd-Queue-Id: A93234001C X-Rspam-User: X-Rspamd-Server: rspam05 X-Stat-Signature: 1b5i8a8gtqaadtz4qegbfp6z5ocb4hmi X-HE-Tag: 1698229823-431823 X-HE-Meta: U2FsdGVkX192LOxhEOKvT/nKhceEsZeuGPBiwj1Wh64U2tLrGMdaeREsFxxbaOqdxvWjxsSsFj5sEC7VDJ0V1B8lgOgR61DnxW197Z3E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sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: 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.