All of lore.kernel.org
 help / color / mirror / Atom feed
From: Hyman Huang <huangy81@chinatelecom.cn>
To: Peter Xu <peterx@redhat.com>
Cc: "Eduardo Habkost" <eduardo@habkost.net>,
	"David Hildenbrand" <david@redhat.com>,
	"Juan Quintela" <quintela@redhat.com>,
	"Richard Henderson" <richard.henderson@linaro.org>,
	qemu-devel <qemu-devel@nongnu.org>,
	"Markus ArmBruster" <armbru@redhat.com>,
	"Paolo Bonzini" <pbonzini@redhat.com>,
	"Philippe Mathieu-Daudé" <philmd@redhat.com>,
	"Dr. David Alan Gilbert" <dgilbert@redhat.com>
Subject: Re: [PATCH v14 6/7] softmmu/dirtylimit: Implement virtual CPU throttle
Date: Mon, 14 Feb 2022 17:05:38 +0800	[thread overview]
Message-ID: <b9c33974-7c1d-5efd-5667-cd705775e501@chinatelecom.cn> (raw)
In-Reply-To: <YgoQxbzrNleQT9TH@xz-m1.local>



在 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.
Sure.
> 
> [...]
> 
>> +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.
Ok, 'adjust' is fine.
> 
> Again, I'd rather call the function directly..
Um, maybe using the function pointer is more extensible.

[...]
static void *vcpu_dirty_rate_stat_thread(void *opaque)
{
     rcu_register_thread();

     /* start log sync */
     global_dirty_log_change(GLOBAL_DIRTY_LIMIT, true);

     while (qatomic_read(&vcpu_dirty_rate_stat->running)) {
         vcpu_dirty_rate_stat_collect();
         if (dirtylimit_in_service() &&
             dirtylimit_state->setup) {
             dirtylimit_state->setup();
         }
     }

     /* stop log sync */
     global_dirty_log_change(GLOBAL_DIRTY_LIMIT, false);

     rcu_unregister_thread();
     return NULL;
}
[...]

Function pointer makes the 'dirtyrate-stat' logic and 'dirtylimit' logic 
kind of decoupled.

But i'm ok if you insist because it's just about how to call the 
'dirtylimit' and doesn't affect the whole logic.

> 
> [...]
> 
>> +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?
> 
>> +    } 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?
> 
>> +    } else {
>> +        dirtylimit_set_throttle(cpu, quota, current);
>> +    }
>> +end:
> 
> Can be dropped?
> 
>> +    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?
> 
>> +        }
>> +
>> +        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?
> 
> Thanks,
> 

-- 
Best regard

Hyman Huang(黄勇)


  reply	other threads:[~2022-02-14  9:10 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-02-10 16:17 [PATCH v14 0/7] support dirty restraint on vCPU huangy81
2022-02-10 16:17 ` [PATCH v14 1/7] accel/kvm/kvm-all: Refactor per-vcpu dirty ring reaping huangy81
2022-02-14  7:57   ` Peter Xu
2022-02-10 16:17 ` [PATCH v14 2/7] cpus: Introduce cpu_list_generation_id huangy81
2022-02-14  7:59   ` Peter Xu
2022-02-10 16:17 ` [PATCH v14 3/7] migration/dirtyrate: Refactor dirty page rate calculation huangy81
2022-02-14  7:57   ` Peter Xu
2022-02-14  8:40     ` Hyman Huang
2022-02-14  9:47       ` Peter Xu
2022-02-10 16:17 ` [PATCH v14 4/7] softmmu/dirtylimit: Implement vCPU dirtyrate calculation periodically huangy81
2022-02-14  8:01   ` Peter Xu
2022-02-10 16:17 ` [PATCH v14 5/7] accel/kvm/kvm-all: Introduce kvm_dirty_ring_size function huangy81
2022-02-14  8:02   ` Peter Xu
2022-02-10 16:17 ` [PATCH v14 6/7] softmmu/dirtylimit: Implement virtual CPU throttle huangy81
2022-02-14  8:20   ` Peter Xu
2022-02-14  9:05     ` Hyman Huang [this message]
2022-02-14  9:51       ` Peter Xu
2022-02-14  9:22     ` Hyman Huang
2022-02-10 16:17 ` [PATCH v14 7/7] softmmu/dirtylimit: Implement dirty page rate limit huangy81
2022-02-11 13:40   ` Markus Armbruster
2022-02-14  8:25   ` Peter Xu
2022-02-14  9:24     ` Hyman Huang

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=b9c33974-7c1d-5efd-5667-cd705775e501@chinatelecom.cn \
    --to=huangy81@chinatelecom.cn \
    --cc=armbru@redhat.com \
    --cc=david@redhat.com \
    --cc=dgilbert@redhat.com \
    --cc=eduardo@habkost.net \
    --cc=pbonzini@redhat.com \
    --cc=peterx@redhat.com \
    --cc=philmd@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=quintela@redhat.com \
    --cc=richard.henderson@linaro.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.