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 X-Spam-Level: X-Spam-Status: No, score=-16.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id AF833C433E0 for ; Mon, 8 Feb 2021 22:29:58 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 2E8FC64EA1 for ; Mon, 8 Feb 2021 22:29:57 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 2E8FC64EA1 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:42282 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l9F2a-0001Pn-TG for qemu-devel@archiver.kernel.org; Mon, 08 Feb 2021 17:29:56 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:50828) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l9BCj-0003ej-JW for qemu-devel@nongnu.org; Mon, 08 Feb 2021 13:24:10 -0500 Received: from mail-wm1-x331.google.com ([2a00:1450:4864:20::331]:40452) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1l9BCi-0006KW-0u for qemu-devel@nongnu.org; Mon, 08 Feb 2021 13:24:09 -0500 Received: by mail-wm1-x331.google.com with SMTP id o24so43576wmh.5 for ; Mon, 08 Feb 2021 10:24:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=cN1ZcZPR2RGrOQpA8sK4oqGTYEHRS4ZzRRQsbqTSWis=; b=OcFGOQ5pHzNDFIIbsee46MvK5f2nF/yFcxQ453WF8falY8uh84CG5/ZtQ6LEWwLCiv +T2Zh+uB5J1m4pP1IdqJdcleWyb1a5y6NzE1DENir+cB+UNzDnmIgla9FShKImny5h+9 iC4KoOckj9ymKO7jquxMm8W2F4ArffPL0zchgB122zjgy5q0bxjZCADpbMQbfI+JA+RS mMFcgn6vSjZk5VjSJfqLOJ2Chw4drHGJkvf1DdxzyX/0dqRkR9gaqSPvENrSgEyOE0eA bNvkiXaSSZhCPwUYBkNEYj2n2AkLS5AMFtnB/VfFPBxL6EpvwZMMctMqKk4q7hp8uICd QYzw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=cN1ZcZPR2RGrOQpA8sK4oqGTYEHRS4ZzRRQsbqTSWis=; b=R4zAFZIM/Fh8wS+ycry5nUVUzKIsSOsiSkP4EYbWpbH+eSkBfxuAxjDZbb0bzksokF aKbc6WToMlMIwUujHWPhFzA6SaGbfvd2or2cm5GZBZsPoZo8RvjsBM8oflnOyZIfKGno oPYHA2T5x1ITyxqtZ5hMxzSBcuqO+d7gY+7sHfcMqekd76sz1A0WX2b4wpiTWKtRpAqz R+ypZedmFMV1eW3hYm+Tjz/9yIXJsM8to5haPLBkDKSw+dbh3JvpsY4jieDwOCLCNV0/ jixJX9oHV/pKDf0aFYT381GarMAwnHW9QMPfAoE56PCYEgvL32XJxJcnDwkHs2dMr8k6 XeNg== X-Gm-Message-State: AOAM5328G5XdsJByUhV7quW7GaXXPRa9Noeiv9JzoWVrs3BMOBS6NA1N kixEG5XiYVRzBGB4h6ifT2WGzzUWIDwjCw== X-Google-Smtp-Source: ABdhPJyf5i5jTekJeH2QHw6zJTNBolH4NvRUScT2vuSdEb3P013PneRJccSzKBGFYYwzK3VCd2pcFg== X-Received: by 2002:a1c:f706:: with SMTP id v6mr49532wmh.85.1612808646765; Mon, 08 Feb 2021 10:24:06 -0800 (PST) Received: from avogadro.redhat.com ([2001:b07:6468:f312:c8dd:75d4:99ab:290a]) by smtp.gmail.com with ESMTPSA id x22sm19670wmc.25.2021.02.08.10.24.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 08 Feb 2021 10:24:06 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PULL 36/46] cpu-throttle: Remove timer_mod() from cpu_throttle_set() Date: Mon, 8 Feb 2021 19:23:21 +0100 Message-Id: <20210208182331.58897-37-pbonzini@redhat.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20210208182331.58897-1-pbonzini@redhat.com> References: <20210208182331.58897-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Received-SPF: pass client-ip=2a00:1450:4864:20::331; envelope-from=paolo.bonzini@gmail.com; helo=mail-wm1-x331.google.com X-Spam_score_int: -14 X-Spam_score: -1.5 X-Spam_bar: - X-Spam_report: (-1.5 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FORGED_FROMDOMAIN=0.248, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.249, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Utkarsh Tripathi Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" From: Utkarsh Tripathi During migrations, after each iteration, cpu_throttle_set() is called, which irrespective of input, re-arms the timer according to value of new_throttle_pct. This causes cpu_throttle_thread() to be delayed in getting scheduled and consqeuntly lets guest run for more time than what the throttle value should allow. This leads to spikes in guest throughput at high cpu-throttle percentage whenever cpu_throttle_set() is called. A solution would be not to modify the timer immediately in cpu_throttle_set(), instead, only modify throttle_percentage so that the throttle would automatically adjust to the required percentage when cpu_throttle_timer_tick() is invoked. Manually tested the patch using following configuration: Guest: Centos7 (3.10.0-123.el7.x86_64) Total Memory - 64GB , CPUs - 16 Tool used - stress (1.0.4) Workload - stress --vm 32 --vm-bytes 1G --vm-keep Migration Parameters: Network Bandwidth - 500MBPS cpu-throttle-initial - 99 Results: With timer_mod(): fails to converge, continues indefinitely Without timer_mod(): converges in 249 sec Signed-off-by: Utkarsh Tripathi Message-Id: <1609420384-119407-1-git-send-email-utkarsh.tripathi@nutanix.com> Signed-off-by: Paolo Bonzini --- softmmu/cpu-throttle.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/softmmu/cpu-throttle.c b/softmmu/cpu-throttle.c index 2ec4b8e0bc..8c2144ab95 100644 --- a/softmmu/cpu-throttle.c +++ b/softmmu/cpu-throttle.c @@ -90,14 +90,21 @@ static void cpu_throttle_timer_tick(void *opaque) void cpu_throttle_set(int new_throttle_pct) { + /* + * boolean to store whether throttle is already active or not, + * before modifying throttle_percentage + */ + bool throttle_active = cpu_throttle_active(); + /* Ensure throttle percentage is within valid range */ new_throttle_pct = MIN(new_throttle_pct, CPU_THROTTLE_PCT_MAX); new_throttle_pct = MAX(new_throttle_pct, CPU_THROTTLE_PCT_MIN); qatomic_set(&throttle_percentage, new_throttle_pct); - timer_mod(throttle_timer, qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL_RT) + - CPU_THROTTLE_TIMESLICE_NS); + if (!throttle_active) { + cpu_throttle_timer_tick(NULL); + } } void cpu_throttle_stop(void) -- 2.29.2