Received: by 2002:a05:7412:bbc7:b0:fc:a2b0:25d7 with SMTP id kh7csp17173rdb; Thu, 1 Feb 2024 00:09:24 -0800 (PST) X-Google-Smtp-Source: AGHT+IEz2SWuwqulA748b6p8zsOGYS1owo7B2PHXSEc7Fa7RMBkY62KkEdlrMOSCcmlzkNz6mdpX X-Received: by 2002:aa7:cd0c:0:b0:55f:c08d:9b13 with SMTP id b12-20020aa7cd0c000000b0055fc08d9b13mr369166edw.41.1706774964191; Thu, 01 Feb 2024 00:09:24 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706774964; cv=pass; d=google.com; s=arc-20160816; b=sJZDEbjwtfY89HfGgOH04Lj5c2l8v3i9xg0LLmH/3ZM+J4JMjkrNyR4XGjSdrlrwUd 5BUiYJbGssO/ouRTLvmfx9ANg3fENanqDfZ+92y6ADRpjPsY+ngSwdB59cGEdfi371cj kY80M0o0Px/p53o3OE+RLYfelcnw0D3dVLMBxOFwy/xuadaGdEi5LREkezFs1PBiJTQz toZCH5O2vN6s6RIy+ZsqZxtFhGPUtRezbqdLzv/T1VVtZgoRFWWr0e3HbddiOGI2HugG nkHb3uTPJll7qpooeKNyV1oUirLST4k6+s4vWTOmfmkVHP1uSIFieyYXNUjQOIu63vSJ MLZw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:date:dkim-signature; bh=iy0to9gJNsnChVp/GnNaL86E7YakxrA6m3SgledDRmM=; fh=F/M3AYyWsf54rXe3DWkBwFFDOmaQwM+staS/nC5/zc4=; b=UZSKW2ueDsiT2X4Z48KA2JOwfo05kXKkVyzce73XWH0aRcLt+JeHV7fEBP84GYVtwl b4J3sWygJtZsirzdVCdvx9MNkDZdRNx/9UuylTCgeyb3NCgdQBWxv9ZVEcGUC1pifnGq bfcbumaU0svIjJNLFP+bkC047Ool4Hvl9xAHwLaH7akGSg1fJ/MsxUF2GHlVPMV9Kenx Rz1xPx/qNgbvA44TpBvm8Dcwa0cHLI2FAyDuAiEKwFwYFvRMNZR0Cj8ABive7TtC3jam XW7fjX7wvV4ROdmp8mDr+TKsdQzlSPvl3SMpozI8HlUEeKaer9XxEMMzFsQNruo3h320 fmWQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=KUf9fVqL; arc=pass (i=1 spf=pass spfdomain=redhat.com dkim=pass dkdomain=redhat.com dmarc=pass fromdomain=redhat.com); spf=pass (google.com: domain of linux-kernel+bounces-47758-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-47758-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com X-Forwarded-Encrypted: i=1; AJvYcCWeb77o8KSjp1BGX7XLI4rvvjevlYo1yiaRerBl1Z+HWFwCIynbTIF/pixdWE5gFbvInUg8qDcwSyQVy0jGeWZzrQ7MQUAuYu/kjMwU2A== Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id o9-20020a056402444900b0055f8e93fae2si1353732edb.22.2024.02.01.00.09.24 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 01 Feb 2024 00:09:24 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-47758-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=KUf9fVqL; arc=pass (i=1 spf=pass spfdomain=redhat.com dkim=pass dkdomain=redhat.com dmarc=pass fromdomain=redhat.com); spf=pass (google.com: domain of linux-kernel+bounces-47758-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-47758-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id BF44A1F23031 for ; Thu, 1 Feb 2024 08:09:23 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 452041586D3; Thu, 1 Feb 2024 08:08:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="KUf9fVqL" Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3C9B61586EF for ; Thu, 1 Feb 2024 08:08:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706774907; cv=none; b=d+Y0OPFDnXdYtD6NM4/6tN/2rWXpBbgPOzqWH1NVWtrD8ZM34LPITrYJT11LnVSxI9UQY6mTm1W0V0kYmgxteabyl3W6B7gBmvj+HL8gb7s+N41lXIQCFL2xuOHkALrGiDyYob2Rj/1kw6IGxu7L6ksDI8PXwg9hDpbnLtxTD6o= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706774907; c=relaxed/simple; bh=yRW+zk6ipQx+/UeKBycRl86N7OpB8VApca3JZVyt31I=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=phR+6fmlyjKOjSQ6u3eGLznEpmaY6nZSNh78hNUCFAiKUug94AwFztkCfKVVCUytmmUFA79qsoL8d2EgSZ4cJvX8Bl9Bia1IPK3Q4UC6WvtIUw0a4++KWIlqHLUJQd0+PohD6GoF03FcrUdBX6ka10p+LXgwZb1Go5EyS7OEduc= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=KUf9fVqL; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1706774896; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=iy0to9gJNsnChVp/GnNaL86E7YakxrA6m3SgledDRmM=; b=KUf9fVqL2VNKyOK/W4u2vJjGcoR0ZzK0JfOARQOruN+EmAIoApqVfkDNm5N83wlLezXF8z hgy9yuQeD7uiATwZR6OojRBpzEExLxt2NxnP/Hjq5LVtdSxNveoDBgC4d7FB3DdrFTiUB9 v5cQ0Y3GDeZx20dShwcSQBJ6rjWjrcY= Received: from mail-ej1-f69.google.com (mail-ej1-f69.google.com [209.85.218.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-631-NlTrKZTYO-OFoidYh4TIuw-1; Thu, 01 Feb 2024 03:08:15 -0500 X-MC-Unique: NlTrKZTYO-OFoidYh4TIuw-1 Received: by mail-ej1-f69.google.com with SMTP id a640c23a62f3a-a2b6c2a5fddso38075666b.1 for ; Thu, 01 Feb 2024 00:08:15 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706774894; x=1707379694; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=iy0to9gJNsnChVp/GnNaL86E7YakxrA6m3SgledDRmM=; b=rk+AMrkKwszY65oPUVTvxbplgN+qgqzsU9I86j2eLU4mBrPGYr6C09/qJuNBFCXKKb zot/UbkSDH69kGOBlJsK4RTaOYO4pgcNOeTziGL1GTTMEondSjCIf/T2O6wLoKO2aIix mCfrjbQmRQP5189kSEyVrqnP3LnqcoOaHCe5lOFjC9GcezUcMM/OpsWrTkmq++QDI13M PQ+dL+kJR/CjGXB+CiOEIdo06T34Osq22VjjIFXc+buLr6HimcQKRrqgnTO2ayt4bpyo MIjyZ5hOtvwXr1oqcysk1i/JTMYDTarCZuf6GtOic/iyewCoQBumpnndQpMztHJ1FDNn qNCw== X-Gm-Message-State: AOJu0YwBLlI76JuZLKxuCYfXS5XBt7djaDUf0VDG22ntIAWnYaVrPP3e HJVUXQqDrGK+NfMUuDw82mKEVcu2c6T0nznJlyTTkBJd3bT3O86rV7arAiDH0ZUlGLBVGa1SG/E 6i25NwWYouuktnAHIpVL7Lng9Y/bKnCj0tBDbb1+VPNd1QUlnJ+pz09SQDYYG3I5JKXORwQ== X-Received: by 2002:a17:907:994a:b0:a36:6198:3505 with SMTP id kl10-20020a170907994a00b00a3661983505mr2891732ejc.25.1706774893759; Thu, 01 Feb 2024 00:08:13 -0800 (PST) X-Received: by 2002:a17:907:994a:b0:a36:6198:3505 with SMTP id kl10-20020a170907994a00b00a3661983505mr2891712ejc.25.1706774893374; Thu, 01 Feb 2024 00:08:13 -0800 (PST) X-Forwarded-Encrypted: i=0; AJvYcCUPikGwlmK61HBD824LPki9FCPfzBqA8DOG1qFKTu86qM6TT3O5V9/CvItrJ98+QzfcVoEyp+96Zr1Nn2L+BvS4DqHAaoL3vKwZ6lp6Isco+Twi35RKwnoZUuMkraXf3k7IhNqwNPtWxXU0q5hpZ3dtYMws/l0G/WLT2JxU+Az61Ph3wfFwo0rWQrE9KpQ7vopZeP4GRY7hV6XC5TPZ8jR/tHxE8mlGsfTD2vqlwVDFVHk3t88eeqmNpQtAeXcq4Z1TDE9naso78eI= Received: from redhat.com ([2a02:14f:179:3a6d:f252:c632:3893:a2ef]) by smtp.gmail.com with ESMTPSA id m1-20020a1709062b8100b00a363e8be473sm2143643ejg.143.2024.02.01.00.08.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 01 Feb 2024 00:08:12 -0800 (PST) Date: Thu, 1 Feb 2024 03:08:07 -0500 From: "Michael S. Tsirkin" To: Tobias Huschle Cc: Jason Wang , Abel Wu , Peter Zijlstra , Linux Kernel , kvm@vger.kernel.org, virtualization@lists.linux.dev, netdev@vger.kernel.org Subject: Re: Re: Re: EEVDF/vhost regression (bisected to 86bfbb7ce4f6 sched/fair: Add lag based placement) Message-ID: <20240201030341-mutt-send-email-mst@kernel.org> References: <20231212111433-mutt-send-email-mst@kernel.org> <42870.123121305373200110@us-mta-641.us.mimecast.lan> <20231213061719-mutt-send-email-mst@kernel.org> <25485.123121307454100283@us-mta-18.us.mimecast.lan> <20231213094854-mutt-send-email-mst@kernel.org> <20231214021328-mutt-send-email-mst@kernel.org> <92916.124010808133201076@us-mta-622.us.mimecast.lan> <20240121134311-mutt-send-email-mst@kernel.org> <07974.124020102385100135@us-mta-501.us.mimecast.lan> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <07974.124020102385100135@us-mta-501.us.mimecast.lan> On Thu, Feb 01, 2024 at 08:38:43AM +0100, Tobias Huschle wrote: > On Sun, Jan 21, 2024 at 01:44:32PM -0500, Michael S. Tsirkin wrote: > > On Mon, Jan 08, 2024 at 02:13:25PM +0100, Tobias Huschle wrote: > > > On Thu, Dec 14, 2023 at 02:14:59AM -0500, Michael S. Tsirkin wrote: > > > - Along with the wakeup of the kworker, need_resched needs to > > > be set, such that cond_resched() triggers a reschedule. > > > > Let's try this? Does not look like discussing vhost itself will > > draw attention from scheduler guys but posting a scheduling > > patch probably will? Can you post a patch? > > As a baseline, I verified that the following two options fix > the regression: > > - replacing the cond_resched in the vhost_worker function with a hard > schedule > - setting the need_resched flag using set_tsk_need_resched(current) > right before calling cond_resched > > I then tried to find a better spot to put the set_tsk_need_resched > call. > > One approach I found to be working is setting the need_resched flag > at the end of handle_tx and hande_rx. > This would be after data has been actually passed to the socket, so > the originally blocked kworker has something to do and will profit > from the reschedule. > It might be possible to go deeper and place the set_tsk_need_resched > call to the location right after actually passing the data, but this > might leave us with sprinkling that call in multiple places and > might be too intrusive. > Furthermore, it might be possible to check if an error occured when > preparing the transmission and then skip the setting of the flag. > > This would require a conceptual decision on the vhost side. > This solution would not touch the scheduler, only incentivise it to > do the right thing for this particular regression. > > Another idea could be to find the counterpart that initiates the > actual data transfer, which I assume wakes up the kworker. From > what I gather it seems to be an eventfd notification that ends up > somewhere in the qemu code. Not sure if that context would allow > to set the need_resched flag, nor whether this would be a good idea. > > > > > > - On cond_resched(), verify if the consumed runtime of the caller > > > is outweighing the negative lag of another process (e.g. the > > > kworker) and schedule the other process. Introduces overhead > > > to cond_resched. > > > > Or this last one. > > On cond_resched itself, this will probably only be possible in a very > very hacky way. That is because currently, there is no immidiate access > to the necessary data available, which would make it necessary to > bloat up the cond_resched function quite a bit, with a probably > non-negligible amount of overhead. > > Changing other aspects in the scheduler might get us in trouble as > they all would probably resolve back to the question "What is the magic > value that determines whether a small task not being scheduled justifies > setting the need_resched flag for a currently running task or adjusting > its lag?". As this would then also have to work for all non-vhost related > cases, this looks like a dangerous path to me on second thought. > > > -------- Summary -------- > > In my (non-vhost experience) opinion the way to go would be either > replacing the cond_resched with a hard schedule or setting the > need_resched flag within vhost if the a data transfer was successfully > initiated. It will be necessary to check if this causes problems with > other workloads/benchmarks. Yes but conceptually I am still in the dark on whether the fact that periodically invoking cond_resched is no longer sufficient to be nice to others is a bug, or intentional. So you feel it is intentional? I propose a two patch series then: patch 1: in this text in Documentation/kernel-hacking/hacking.rst If you're doing longer computations: first think userspace. If you **really** want to do it in kernel you should regularly check if you need to give up the CPU (remember there is cooperative multitasking per CPU). Idiom:: cond_resched(); /* Will sleep */ replace cond_resched -> schedule Since apparently cond_resched is no longer sufficient to make the scheduler check whether you need to give up the CPU. patch 2: make this change for vhost. WDYT? -- MST