All of lore.kernel.org
 help / color / mirror / Atom feed
From: Dan Carpenter <dan.carpenter@oracle.com>
To: ggherdovich@suse.cz
Cc: kernel-janitors@vger.kernel.org
Subject: [bug report] x86, sched: Bail out of frequency invariance if turbo frequency is unknown
Date: Thu, 5 May 2022 10:05:23 +0300	[thread overview]
Message-ID: <YnN3MwU5lPoNXhWU@kili> (raw)

Hello Giovanni Gherdovich,

The patch 51beea8862a3: "x86, sched: Bail out of frequency invariance
if turbo frequency is unknown" from May 31, 2020, leads to the
following Smatch static checker warning:

	arch/x86/kernel/cpu/aperfmperf.c:274 intel_set_max_freq_ratio()
	error: uninitialized symbol 'turbo_freq'.

arch/x86/kernel/cpu/aperfmperf.c
    242 static bool __init intel_set_max_freq_ratio(void)
    243 {
    244         u64 base_freq, turbo_freq;
    245         u64 turbo_ratio;
    246 
    247         if (slv_set_max_freq_ratio(&base_freq, &turbo_freq))
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Imagine this fails.

    248                 goto out;
    249 
    250         if (x86_match_cpu(has_glm_turbo_ratio_limits) &&
    251             skx_set_max_freq_ratio(&base_freq, &turbo_freq, 1))
    252                 goto out;
    253 
    254         if (x86_match_cpu(has_knl_turbo_ratio_limits) &&
    255             knl_set_max_freq_ratio(&base_freq, &turbo_freq, 1))
    256                 goto out;
    257 
    258         if (x86_match_cpu(has_skx_turbo_ratio_limits) &&
    259             skx_set_max_freq_ratio(&base_freq, &turbo_freq, 4))
    260                 goto out;
    261 
    262         if (core_set_max_freq_ratio(&base_freq, &turbo_freq))
    263                 goto out;
    264 
    265         return false;
    266 
    267 out:
    268         /*
    269          * Some hypervisors advertise X86_FEATURE_APERFMPERF
    270          * but then fill all MSR's with zeroes.
    271          * Some CPUs have turbo boost but don't declare any turbo ratio
    272          * in MSR_TURBO_RATIO_LIMIT.
    273          */
--> 274         if (!base_freq || !turbo_freq) {
                    ^^^^^^^^^^^^^^^^^^^^^^^^^
Uninitialized.  Although I notice that base_freq is also unintialized
and that predates your patch...  So I should probably send this bug
report to someone else...  Sorry?

    275                 pr_debug("Couldn't determine cpu base or turbo frequency, necessary for scale-invariant accounting.\n");
    276                 return false;
    277         }
    278 
    279         turbo_ratio = div_u64(turbo_freq * SCHED_CAPACITY_SCALE, base_freq);
    280         if (!turbo_ratio) {
    281                 pr_debug("Non-zero turbo and base frequencies led to a 0 ratio.\n");
    282                 return false;
    283         }
    284 
    285         arch_turbo_freq_ratio = turbo_ratio;
    286         arch_set_max_freq_ratio(turbo_disabled());
    287 
    288         return true;
    289 }

regards,
dan carpenter

             reply	other threads:[~2022-05-05  7:05 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-05-05  7:05 Dan Carpenter [this message]
2022-05-13  8:15 ` [bug report] x86, sched: Bail out of frequency invariance if turbo frequency is unknown Giovanni Gherdovich
2022-05-13 13:17 ` Giovanni Gherdovich
2022-05-13 14:05   ` Dan Carpenter
2022-05-13 14:40     ` Giovanni Gherdovich

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=YnN3MwU5lPoNXhWU@kili \
    --to=dan.carpenter@oracle.com \
    --cc=ggherdovich@suse.cz \
    --cc=kernel-janitors@vger.kernel.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.