From nobody Sat Nov 23 15:49:22 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=reject dis=none) header.from=citrix.com ARC-Seal: i=1; a=rsa-sha256; t=1724767097; cv=none; d=zohomail.com; s=zohoarc; b=jfSX0FCkeIFkX12lhZZtmkJCXVHdY3BZR9552qNd30m+DEwp8/0yvDJP9GWcHntLvR1ub/Xyg7XOscTGlD4/JjS6SNExqPlYtlg+24Nvc6xsUct/40dAhjQJvrUOAUH948DAk+H3xGhuDh/duyhsviXVYGJ56ZNgTWX+XBzgotE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1724767097; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=nGUfx2q1+jWgi8jP5MwYlvDEDt5Tq995qxqKh3B4e+k=; b=R+8hedVym0kxxeD8Kf2f01143MhM5fnpzkdkb3Xv+idh33bGCR6LtYcpTM3jZ5qSr8NcUBukkZ9WIJy30RIst/tRpTxHTxnMv2Hyfgf5WLXuK0wNALz+cEA6CXDfOU/V+Hr0JH4wLS+wkYp+5eXOiYOjGPhfKMboTvuUcgUZ5PE= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=reject dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1724767097344803.5580427149206; Tue, 27 Aug 2024 06:58:17 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.784072.1193470 (Exim 4.92) (envelope-from ) id 1siwhs-0004xV-1m; Tue, 27 Aug 2024 13:58:00 +0000 Received: by outflank-mailman (output) from mailman id 784072.1193470; Tue, 27 Aug 2024 13:57:59 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1siwhr-0004wO-RO; Tue, 27 Aug 2024 13:57:59 +0000 Received: by outflank-mailman (input) for mailman id 784072; Tue, 27 Aug 2024 13:57:58 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1siwhq-0003sI-6S for xen-devel@lists.xenproject.org; Tue, 27 Aug 2024 13:57:58 +0000 Received: from mail-ej1-x62e.google.com (mail-ej1-x62e.google.com [2a00:1450:4864:20::62e]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 5ca9fc5d-647c-11ef-99a0-01e77a169b0f; Tue, 27 Aug 2024 15:57:56 +0200 (CEST) Received: by mail-ej1-x62e.google.com with SMTP id a640c23a62f3a-a7aa086b077so493904266b.0 for ; Tue, 27 Aug 2024 06:57:56 -0700 (PDT) Received: from andrewcoop.eng.citrite.net ([185.25.67.249]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a86e588adf2sm113898966b.173.2024.08.27.06.57.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Aug 2024 06:57:54 -0700 (PDT) X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 5ca9fc5d-647c-11ef-99a0-01e77a169b0f DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=citrix.com; s=google; t=1724767076; x=1725371876; darn=lists.xenproject.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=nGUfx2q1+jWgi8jP5MwYlvDEDt5Tq995qxqKh3B4e+k=; b=DHLiiCoBRMXFoVCaBxdOlLd8jCuJ7jxvy1jvJg81HN0sZuf1lwh7cRYKOm2Y2IfXAO dUtgyBfBI+GPZkmb6+NpJNk+pOa256bpX+2tAVipjjk2fFL+UCyRVh9tX2WS235UYPDm vUVD3Zbn4gT4YUA4EHC/yGqik3u4RFZPc1bSs= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724767076; x=1725371876; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=nGUfx2q1+jWgi8jP5MwYlvDEDt5Tq995qxqKh3B4e+k=; b=ZBsXRgC7NTkQqkwIToFL/xtBLTfT6/33hwP7+7HzyxV0o5xHAWacl+kLStVHkizGDq M9JIiHy3lmLiBksNwYgsmnqDQy+jRWgT9NRHn84Qk9YYZZI7YJamEVmCMVWbN11+M/+o dwb0fRun+u0igKtay51RPCI6IdQLWo2QqxfkDTMovl2uY3EEExpWqTJ+HfaRD8AjHQbn kanAhLeKVBPwTy3lJmsrilb30ldbk+8zYHQVhpC6EedLtUGbdWvj0yIQyjkvjNE7Pic6 PEmuUuDBXDw3DF1vmxeHCVvrGfzF4YQOiPD4I4v6rBAoZwRA7qAl/SJ0DQcSCtU8QtOz rGPw== X-Gm-Message-State: AOJu0Yz6HxO13k8do/s9Jn1kOEIV1dHXr7LYeMYlCtcgPveJLglF5aRf tQXhYLO/QN05ayschIp6z8qQGEu7N2BAkkxHtY+OJvoT9vrVkPN68+niO9GN5kO/sydnm7qQQwn a X-Google-Smtp-Source: AGHT+IF+lE+VmLKB8gnLP/DI0Jsj0j8worRIiuKlHU8MrF0gDq9Q5hJgWjAvzf9gxSKUf9uxlYP8Dw== X-Received: by 2002:a17:907:7e9a:b0:a86:a4b1:d2c0 with SMTP id a640c23a62f3a-a86a54b8ce4mr1167977166b.53.1724767075121; Tue, 27 Aug 2024 06:57:55 -0700 (PDT) From: Andrew Cooper To: Xen-devel Cc: Andrew Cooper , Jan Beulich , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= Subject: [PATCH 3/4] x86/hvm: Rework hpet_write() for improved code generation Date: Tue, 27 Aug 2024 14:57:45 +0100 Message-Id: <20240827135746.1908070-4-andrew.cooper3@citrix.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240827135746.1908070-1-andrew.cooper3@citrix.com> References: <20240827135746.1908070-1-andrew.cooper3@citrix.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @citrix.com) X-ZM-MESSAGEID: 1724767097883116600 In the HPET_STATUS handling, the use of __clear_bit(i, &new_val) is the only thing causing it to be spilled to the stack. Furthemore we only care about the bottom 3 bits, so rewrite it to be a plain for loop. For the {start,stop}_timer variables, these are spilled to the stack despite the __{set,clear}_bit() calls. Again we only care about the bottom 3 bits,= so shrink the variables from long to int. Use for_each_set_bit() rather than opencoding it at the end which amongst other things means the loop predicate is no longer forced to the stack by the loop body. Signed-off-by: Andrew Cooper --- CC: Jan Beulich CC: Roger Pau Monn=C3=A9 All in all, it's modest according to bloat-o-meter: add/remove: 0/0 grow/shrink: 0/1 up/down: 0/-29 (-29) Function old new delta hpet_write 2225 2196 -29 but we have shrunk the stack frame by 8 bytes; 0x28 as opposed to 0x30 befo= re. --- xen/arch/x86/hvm/hpet.c | 29 ++++++++--------------------- 1 file changed, 8 insertions(+), 21 deletions(-) diff --git a/xen/arch/x86/hvm/hpet.c b/xen/arch/x86/hvm/hpet.c index 87642575f9cd..e3981d5e467c 100644 --- a/xen/arch/x86/hvm/hpet.c +++ b/xen/arch/x86/hvm/hpet.c @@ -349,8 +349,7 @@ static int cf_check hpet_write( unsigned int tn, i; =20 /* Acculumate a bit mask of timers whos state is changed by this write= . */ - unsigned long start_timers =3D 0; - unsigned long stop_timers =3D 0; + unsigned int start_timers =3D 0, stop_timers =3D 0; #define set_stop_timer(n) (__set_bit((n), &stop_timers)) #define set_start_timer(n) (__set_bit((n), &start_timers)) #define set_restart_timer(n) (set_stop_timer(n),set_start_timer(n)) @@ -405,16 +404,12 @@ static int cf_check hpet_write( =20 case HPET_STATUS: /* write 1 to clear. */ - while ( new_val ) + for ( i =3D 0; i < HPET_TIMER_NUM; i++ ) { - bool active; - - i =3D ffsl(new_val) - 1; - if ( i >=3D HPET_TIMER_NUM ) - break; - __clear_bit(i, &new_val); - active =3D __test_and_clear_bit(i, &h->hpet.isr); - if ( active ) + if ( !(new_val & (1U << i)) ) + continue; + + if ( __test_and_clear_bit(i, &h->hpet.isr) ) { hvm_ioapic_deassert(v->domain, timer_int_route(h, i)); if ( hpet_enabled(h) && timer_enabled(h, i) && @@ -533,19 +528,11 @@ static int cf_check hpet_write( } =20 /* stop/start timers whos state was changed by this write. */ - while (stop_timers) - { - i =3D ffsl(stop_timers) - 1; - __clear_bit(i, &stop_timers); + for_each_set_bit ( i, stop_timers ) hpet_stop_timer(h, i, guest_time); - } =20 - while (start_timers) - { - i =3D ffsl(start_timers) - 1; - __clear_bit(i, &start_timers); + for_each_set_bit ( i, start_timers ) hpet_set_timer(h, i, guest_time); - } =20 #undef set_stop_timer #undef set_start_timer --=20 2.39.2