public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [MIPS]clocks_calc_mult_shift() may gen a too big mult value
@ 2011-10-31  9:00 Chen Jie
  2011-10-31  9:20 ` Yong Zhang
  0 siblings, 1 reply; 8+ messages in thread
From: Chen Jie @ 2011-10-31  9:00 UTC (permalink / raw)
  To: linux-mips, LKML
  Cc: johnstul, tglx, yanhua, 项宇, zhangfx,
	孙海勇

[-- Attachment #1: Type: text/plain, Size: 965 bytes --]

Hi all,

On MIPS, with maxsec=4, clocks_calc_mult_shift() may generate a very
big mult, which may easily cause timekeeper.mult overflow within
timekeeping jobs.

e.g. when clock freq was 250000500(i.e. mips_hpt_frequency=250000500,
and the CPU Freq will be 250000500*2=500001000), mult will be
0xffffde72

Attachment is a script that calculates mult values for CPU Freq
between 400050000 and 500050000, with 1KHz step. It outputs mult
values greater than 0xf0000000:
CPU Freq:500001000, mult:0xffffde72, shift:30
CPU Freq:500002000, mult:0xffffbce4, shift:30
CPU Freq:500003000, mult:0xffff9b56, shift:30
CPU Freq:500004000, mult:0xffff79c9, shift:30
...

The peak value appears around CPU_freq=500001000.

To avoid this, it may need:
1. Supply a bigger maxsec value?
2. In clocks_calc_mult_shift(), pick next mult/shift pair if mult is
too big? Then maxsec will not be strictly obeyed.
3. Change timekeeper.mult to u64?
4. ...

Any idea?



--
Regards,
- Chen Jie

[-- Attachment #2: mult-test.py --]
[-- Type: text/x-python, Size: 511 bytes --]

#!/bin/env python

def clocks_calc_mult_shift(from_, to_, maxsec):
	sftacc = 32;

	tmp = maxsec * from_ >> 32;
	while tmp:
		tmp >>= 1
		sftacc -= 1

	for sft in xrange(32, 0, -1):
		tmp = to_ << sft;
		tmp += (from_ / 2)
		tmp /= from_
		if ((tmp >> sftacc) == 0):
			break

	mult = tmp
	shift = sft
	return mult, shift 

for i in xrange(400050000, 500050000, 1000):
	mult, shift = clocks_calc_mult_shift(i/2, 1000000000, 4)
	if mult > 0xf0000000:
		print "CPU Freq:%d, mult:0x%x, shift:%d" % (i, mult, shift)

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2011-10-31 19:59 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-10-31  9:00 [MIPS]clocks_calc_mult_shift() may gen a too big mult value Chen Jie
2011-10-31  9:20 ` Yong Zhang
2011-10-31 10:48   ` Chen Jie
2011-10-31 13:03     ` John Stultz
2011-10-31 13:59       ` zhangfx
2011-10-31 18:12         ` John Stultz
2011-10-31 18:30           ` David Daney
2011-10-31 19:51             ` John Stultz

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox