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 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 smtp.lore.kernel.org (Postfix) with ESMTPS id A599FC433EF for ; Mon, 14 Feb 2022 09:26:17 +0000 (UTC) Received: from localhost ([::1]:46156 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nJXcd-0004Qm-Qy for qemu-devel@archiver.kernel.org; Mon, 14 Feb 2022 04:26:15 -0500 Received: from eggs.gnu.org ([209.51.188.92]:58574) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nJXZg-0003Bl-9U for qemu-devel@nongnu.org; Mon, 14 Feb 2022 04:23:12 -0500 Received: from prt-mail.chinatelecom.cn ([42.123.76.228]:56478 helo=chinatelecom.cn) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nJXZd-0004pQ-Q2 for qemu-devel@nongnu.org; Mon, 14 Feb 2022 04:23:12 -0500 HMM_SOURCE_IP: 172.18.0.48:58916.1587662925 HMM_ATTACHE_NUM: 0000 HMM_SOURCE_TYPE: SMTP Received: from clientip-182.150.57.243 (unknown [172.18.0.48]) by chinatelecom.cn (HERMES) with SMTP id 4A5DB280142; Mon, 14 Feb 2022 17:22:39 +0800 (CST) X-189-SAVE-TO-SEND: huangy81@chinatelecom.cn Received: from ([172.18.0.48]) by app0024 with ESMTP id a3f5fac9771a49eaa058944d7969aa1f for peterx@redhat.com; Mon, 14 Feb 2022 17:23:02 CST X-Transaction-ID: a3f5fac9771a49eaa058944d7969aa1f X-Real-From: huangy81@chinatelecom.cn X-Receive-IP: 172.18.0.48 X-MEDUSA-Status: 0 Message-ID: <6653e941-d082-2672-576f-c6d066ccfd40@chinatelecom.cn> Date: Mon, 14 Feb 2022 17:22:38 +0800 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101 Thunderbird/91.6.0 Subject: Re: [PATCH v14 6/7] softmmu/dirtylimit: Implement virtual CPU throttle To: Peter Xu References: From: Hyman Huang In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Received-SPF: pass client-ip=42.123.76.228; envelope-from=huangy81@chinatelecom.cn; helo=chinatelecom.cn X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, NICE_REPLY_A=-0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Eduardo Habkost , David Hildenbrand , Juan Quintela , Richard Henderson , qemu-devel , Markus ArmBruster , Paolo Bonzini , =?UTF-8?Q?Philippe_Mathieu-Daud=c3=a9?= , "Dr. David Alan Gilbert" Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" 在 2022/2/14 16:20, Peter Xu 写道: > On Fri, Feb 11, 2022 at 12:17:40AM +0800, huangy81@chinatelecom.cn wrote: >> @@ -2964,8 +2971,13 @@ int kvm_cpu_exec(CPUState *cpu) >> */ >> trace_kvm_dirty_ring_full(cpu->cpu_index); >> qemu_mutex_lock_iothread(); >> - kvm_dirty_ring_reap(kvm_state, NULL); >> + if (dirtylimit_in_service()) { >> + kvm_dirty_ring_reap(kvm_state, cpu); >> + } else { >> + kvm_dirty_ring_reap(kvm_state, NULL); >> + } > > Could you add some comment here on why the cpu pointer is conditionally passed > into the reaping routine? Even if we know it now, it's not immediately obvious > to all the readers. > > [...] > >> +struct { >> + VcpuDirtyLimitState *states; >> + /* Max cpus number configured by user */ >> + int max_cpus; >> + /* Number of vcpu under dirtylimit */ >> + int limited_nvcpu; >> + /* Function to implement throttle set up */ >> + DirtyLimitFunc setup; > > "setup" normally is used only at startup of something, but not per interval. > Perhaps "process" or "adjust"? Same across other "setup" namings across the > patch. > > Again, I'd rather call the function directly.. > > [...] > >> +static void dirtylimit_adjust_throttle(CPUState *cpu) >> +{ >> + uint64_t quota = 0; >> + uint64_t current = 0; >> + int cpu_index = cpu->cpu_index; >> + >> + quota = dirtylimit_vcpu_get_state(cpu_index)->quota; >> + current = vcpu_dirty_rate_get(cpu_index); >> + >> + if (current == 0) { >> + cpu->throttle_us_per_full = 0; >> + goto end; > > Can be dropped? Ok, i'll move this block into dirtylimit_set_throttle. > >> + } else if (dirtylimit_done(quota, current)) { >> + goto end; > > Same here. Dropping it wholely and: > > } else if (!dirtylimit_done(quota, current)) { > dirtylimit_set_throttle(cpu, quota, current); > } > > Would work? Yes. > >> + } else { >> + dirtylimit_set_throttle(cpu, quota, current); >> + } >> +end: > > Can be dropped?Ok > >> + trace_dirtylimit_adjust_throttle(cpu_index, >> + quota, current, >> + cpu->throttle_us_per_full); >> + return; >> +} >> + >> +void dirtylimit_setup(void) >> +{ >> + CPUState *cpu; >> + >> + if (!qatomic_read(&dirtylimit_quit)) { >> + dirtylimit_state_lock(); >> + >> + if (!dirtylimit_in_service()) { >> + dirtylimit_state_unlock(); > > Need to return? My fault. :( > >> + } >> + >> + CPU_FOREACH(cpu) { >> + if (!dirtylimit_vcpu_get_state(cpu->cpu_index)->enabled) { >> + continue; >> + } >> + dirtylimit_adjust_throttle(cpu); >> + } >> + dirtylimit_state_unlock(); >> + } >> +} > > [...] > >> +void dirtylimit_set_vcpu(int cpu_index, >> + uint64_t quota, >> + bool enable) >> +{ >> + dirtylimit_vcpu_set_quota(cpu_index, quota, enable); >> + trace_dirtylimit_set_vcpu(cpu_index, quota); >> +} > > This helper is not "help"ful.. How about wrapping the trace into > dirtylimit_vcpu_set_quota, then drop it? > Ok. > Thanks, > -- Best regard Hyman Huang(黄勇)