From: Michal Simek <monstr@monstr.eu>
To: john stultz <johnstul@us.ibm.com>
Cc: Thomas Gleixner 1 <tglx@linutronix.de>,
LKML <linux-kernel@vger.kernel.org>,
john.williams@petalogix.com
Subject: Re: [PATCH 08/57] microblaze_v7: Interrupt handling, timer support, selfmod code
Date: Sat, 21 Mar 2009 11:38:53 +0100 [thread overview]
Message-ID: <49C4C3BD.9090905@monstr.eu> (raw)
In-Reply-To: <1237581607.7191.51.camel@localhost.localdomain>
Hi John,
> On Fri, 2009-03-20 at 08:27 +0100, Michal Simek wrote:
>> Hi John S,
>>
>>> On Thu, 2009-03-19 at 22:47 +0100, Thomas Gleixner wrote:
>>>> On Thu, 19 Mar 2009, Michal Simek wrote:
>>>>> And the second question is about shift and rating values.
>>>>> I wrote one message in past http://lkml.org/lkml/2009/1/11/291
>>>>> Here is the important of part of that message.
>>>>>
>>>>> ...
>>>>>
>>>>> And the second part is about shift and rating values. Rating is
>>>>> describe(linux/clocksource.h) and seems to me that should be
>>>>> corresponded with CONFIG_HZ value,right?
>>> Not sure where the idea of correspondence w/ CONFIG_HZ came from. The
>>> rating value just provides a relative ordering of preferences between
>>> possible clocksources. Since different hardware may have a number of
>>> different clocksources available, we just need to have a method of
>>> selecting a preferred clocksource, and the rating value is used for
>>> that.
>>>
>>> The guide in linux/clocksource.h is just a guide. Most arches, which
>>> only have one or two clocksource options probably won't need much care,
>>> and a rating of 200 or 300 will probably suffice. Or if there really
>>> isn't any option about it and there is only one which is a must-use
>>> clocksource, 400.
>> ok. That mean that for my case (only one clocksource) I should set rating to 400
>> - I have one clocksource and is perfect for me.
>
> As long as there will never be another clocksource used on that
> architecture, 400 is probably ok. Since its sometimes hard to tell, you
> might want to pick a more moderate 300.
>
> But again, its a relative scale and doesn't matter all that much, as
> long as the right clocksource is always selected at boot for the
> hardware.
OK that mean that rating do the same work for clockevent sources too, right?
>
>
>>>>> And I found any explanation of shift value -> max value for equation
>>>>> (2-5) * freq << shift / NSEC_PER_SEC should be for my case still 32bit
>>>>> number, where (2-5s) are because of NTP
>>>> @John, can you explain the shift vlaue please ?
>>> The shift value is a bit more difficult to explain. The algorithm you
>>> describe above is used by sparc to generate shift, and I think it will
>>> work, but may not be optimal.
>>>
>>> This question comes up over and over, so I figured I should sit down and
>>> really solve it.
>>>
>>> Basically the constraint is you want to calculate a mult value using the
>>> highest shift possible. However we have to be careful not to overflow
>>> 64bits when we multiply ~5second worth of cycles times the mult value.
>>>
>>> So I finally put this down into code and here it is. No promises that it
>>> is 100% right, but from my simple test examples it worked ok.
>> OK. Please check my case of that value.
>> MB can run from 5Mhz till 150MHz I think.
>> I need generic approach that's why I have to calculate with max value (150MHz).
>> My timer can tick on that freq too. (There is no different time bases in HW).
>>
>> I need to find out how many ticks takes ~5s.
>> 150MHz means that I need for 1sec 150 000 000 timer ticks.
>
> I think you mean counter cycles instead of timer ticks. Timer tick
> terminology usually describes a timer based interrupt.
yes.
>
>> One tick takes 1/150MHz = ~6-7ns - in the best case I can recognize and set
>> 6-7ns (this is only theoretical value because of overhead)
>>
>> ~5s takes 750 000 000 ticks = 0x2CB4 1780. And I have 32bit counter.
>>
>> That my question is how big could be a shift of value above till overflow.
>> 0x2CB4 1780 << shift not exceed 0xffff ffff ffff ffff.
>
> Almost. Its not the shift that causes the problem right off, but the
> resulting mult value calculated from a shift. Again, the key points are,
> you want to make sure that:
>
> 1) that mult value for the given shift fits in 32 bits.
> and
ok. Formula.
For mult 1GHz * 2^shift/timer_freq < (u32)
=> const=1GHz/timer_freq, const * 2^shift < (u32)
2^30=0x4000 0000
2^29=0x2000 0000
2^28=0x1000 0000
2^26=0x 400 0000
2^25=0x 200 0000
2^24=0x 100 0000
For shift in test
2^20=0x 10 0000
2^8= 0x 100
For 150MHz ->const = 6,6666 -> 30 is over, 29 fits.
For 5MHz -> const = 200 -> 25 is over, 24 fits.
For 1GHz -> const = 1 -> 32 is over, 31 fits - that's correct
For your test case below ->
(5 * timer_freq * 1GHz * 2^shift/timer_freq)>>shift <= 5sec in ns
=>(5 * 1GHz * 2^shift )>>shift <= 5sec in ns
=>( 5GHz * 2^shift )>>shift <= 5sec in ns
=>( 1GHz * 2^shift )>>shift <= 1sec in ns
=> 1GHz <= 1sec in ns
=> I think this is no test -> this is equal for every values.
Am I right?
If yes.
min_delta_ns is set to (const<1000 ? 1000 : const) -> I think that only for
slower machines than 1MHx uses const value.
max_delta_ns is for 32bit timer 2^31 -1 and for 64bit arch 2^63 - 1
> 2) mult * 5sec of cycles doesn't overflow 64bits (really is only an
> issue for very very fast counters that run faster then 1Ghz).
>
>
> So let's follow my algorithm and start by picking a shift value of 32.
>
> We calculate the mult, which would be (using clocksource_khz2mult()):
>
> (1Million * 2^32) / 150,000 = 28633115307 which overflows 32bits.
> BZZZZZZ.
>
> 1Million * 2^31 / 150,000 = 14316557653 (to big. BZZZZZZZ)
>
>
> 1Million * 2^30 / 150,000 = 7158278827 (to big. BZZZZZZZ)
>
>
> 1Million * 2^29 / 150,000 = 3579139413 (BING! it fits!)
>
> Now the test:
> (750 000 000 * 3 579 139 413)>>29 ?= 5 seconds
> 2684354559750000000 (doesn't overflow!) >> 29
> 4999999999ns ?= 5seconds (within the error range, so we're good!)
>
>
> Now take care, because the slower the clocksource, often the lower the
> shift value we can use, because the nsecs per cycle value that mult
> approximates is much larger.
>
>
> So for 5mhz (using
>
> 1Million * 2^29 / 5,000 = 107374182400 (32bit overflow!)
> ...
> 1Million * 2^24 / 5,000 = 3355443200 (fits!)
>
> Now the test:
> (25000000 * 3355443200)>>24 ?= 5 seconds
> 83886080000000000 (doesn't overflow!) >> 24 ?=
> 5000000000ns ?= 5seconds (BING!)
>
>
> So you can either dynamically calculate the best shift value for the
> actual freq using the helper functions I provided, or just use 24 and be
> safe, your pick.
ok. we will talk what the smaller freq is.
>
>
>
>> For example avr has shift 16, rating 50 (arch/avr32/kernel/time.c) (BTW: Sets
>> time from 2007 too)
>
> Most arches probably low ball the shift to be safe. Mainly because
> explaining how to calculate the optimal shift was hard and there weren't
> helper functions.
I hope that our discussion clear this.
>
> As an aside (feel free to ignore for the microblaze bits):
> Some complexity may grow here as well, since 5 seconds of cycles may
> prove too short as folks become more interested running w/ NOHZ and
> avoiding interrupts for extreme lengths of time (I've heard 30
> minutes!?). For those situations we will need lower shift values, since
> 30 minutes of cycles * a large mult value close to (1<<32) will likely
> overflow 64bits. But that trades off how finely we can tweak the clock
> steering. Probably converting folks to use the helper functions will be
> the best approach, as it will allow us to configure that depending on
> NOHZ or not.
ok.Let's talk about NOHZ case.
I enabled NOHZ choice in menuconfig. I am sourcing source two Kconfigs
(kernel/time/Kconfig and kernel/Kconfig.hz)
Here is the fragment from my .config file.
CONFIG_TICK_ONESHOT=y
CONFIG_NO_HZ=y
CONFIG_HIGH_RES_TIMERS=y
CONFIG_GENERIC_CLOCKEVENTS_BUILD=y
CONFIG_PREEMPT_NONE=y
...
CONFIG_HZ_100=y
# CONFIG_HZ_250 is not set
# CONFIG_HZ_300 is not set
# CONFIG_HZ_1000 is not set
CONFIG_HZ=100
For NO_HZ val I shouldn't use HZ value because of NO_HZ and HZ values shouldn't
be in .config file. Am I right?
If yes I have still problem in my code.
I have there these two parts.
Just counting value for periodic mode but depends on HZ value.
cpuinfo.freq_div_hz = cpuinfo.cpu_clock_freq / HZ;
+ usage in periodic mode.
case CLOCK_EVT_MODE_PERIODIC:
printk(KERN_INFO "%s: periodic\n", __func__);
microblaze_timer0_start_periodic(cpuinfo.freq_div_hz);
break;
Here is the part of my kernel log. At the beginning is setup periodic mode and
then is switched to oneshot mode. And for periodic mode I use HZ value which
shouldn't be there.
microblaze_timer_set_mode: shutdown
microblaze_timer_set_mode: periodic
Dentry cache hash table entries: 32768 (order: 5, 131072 bytes)
Inode-cache hash table entries: 16384 (order: 4, 65536 bytes)
Memory: 254848k/262144k available
ODEBUG: selftest passed
Calibrating delay loop... 60.82 BogoMIPS (lpj=304128)
Mount-cache hash table entries: 512
net_namespace: 544 bytes
NET: Registered protocol family 16
bio: create slab <bio-0> at 0
NET: Registered protocol family 2
microblaze_timer_set_mode: oneshot ------------------------- switch to oneshot
Switched to high resolution mode on CPU 0
What is the correct solution for NO_HZ case?
BTW: I just tried to remove Kconfig.hz sourcing and I am getting faults in
include/linux/jiffies.h and I expect the problems in other code too.
Thanks,
Michal
>
> thanks
> -john
>
>
--
Michal Simek, Ing. (M.Eng)
w: www.monstr.eu p: +42-0-721842854
next prev parent reply other threads:[~2009-03-21 10:39 UTC|newest]
Thread overview: 113+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-03-18 20:30 Microblaze linux support monstr
2009-03-18 20:30 ` [PATCH 01/57] microblaze_v7: Kconfig patches monstr
2009-03-18 20:30 ` [PATCH 02/57] microblaze_v7: Makefiles for Microblaze cpu monstr
2009-03-18 20:30 ` [PATCH 03/57] microblaze_v7: Cpuinfo handling monstr
2009-03-18 20:30 ` [PATCH 04/57] microblaze_v7: Open firmware files monstr
2009-03-23 18:51 ` Arnd Bergmann
2009-03-23 20:53 ` Anton Vorontsov
2009-03-26 0:01 ` Benjamin Herrenschmidt
2009-03-24 11:17 ` Michal Simek
2009-03-18 20:30 ` [PATCH 05/57] microblaze_v7: Platorm bus registration monstr
2009-03-18 20:30 ` [PATCH 06/57] microblaze_v7: exception handling monstr
2009-03-18 20:30 ` [PATCH 07/57] microblaze_v7: Signal support monstr
2009-03-23 19:35 ` Arnd Bergmann
2009-03-24 11:14 ` Michal Simek
2009-03-18 20:30 ` [PATCH 08/57] microblaze_v7: Interrupt handling, timer support, selfmod code monstr
2009-03-19 15:49 ` Thomas Gleixner
2009-03-19 20:28 ` Michal Simek
2009-03-19 21:47 ` Thomas Gleixner
2009-03-20 2:24 ` John Stultz
2009-03-20 7:27 ` Michal Simek
2009-03-20 20:40 ` john stultz
2009-03-21 10:38 ` Michal Simek [this message]
2009-03-21 11:14 ` Thomas Gleixner
2009-03-21 11:57 ` Michal Simek
2009-03-21 12:05 ` Thomas Gleixner
2009-03-21 12:07 ` Michal Simek
2009-03-20 6:38 ` Michal Simek
2009-03-20 10:07 ` Thomas Gleixner
2009-03-20 9:26 ` Michal Simek
2009-03-20 9:58 ` Thomas Gleixner
2009-03-20 10:37 ` Michal Simek
2009-03-20 10:49 ` Thomas Gleixner
2009-03-20 11:28 ` Michal Simek
2009-03-20 11:41 ` Thomas Gleixner
2009-03-20 11:59 ` Michal Simek
2009-03-20 14:08 ` Michal Simek
2009-03-20 14:12 ` Thomas Gleixner
2009-03-20 14:27 ` Michal Simek
2009-03-18 20:30 ` [PATCH 09/57] microblaze_v7: cache support monstr
2009-03-18 20:30 ` [PATCH 10/57] microblaze_v7: Generic dts file for platforms monstr
2009-03-18 20:30 ` [PATCH 11/57] microblaze_v7: kernel modules support monstr
2009-03-18 20:30 ` [PATCH 12/57] microblaze_v7: lmb include file monstr
2009-03-18 20:30 ` [PATCH 13/57] microblaze_v7: PVR support, cpuinfo support monstr
2009-03-18 20:30 ` [PATCH 14/57] microblaze_v7: defconfig file monstr
2009-03-18 20:30 ` [PATCH 15/57] microblaze_v7: assembler files head.S, entry-nommu.S, syscall_table.S monstr
2009-03-18 20:30 ` [PATCH 16/57] microblaze_v7: vmlinux.lds.S - linker script monstr
2009-03-18 20:30 ` [PATCH 17/57] microblaze_v7: supported function for memory - kernel/lib monstr
2009-03-18 20:30 ` [PATCH 18/57] microblaze_v7: checksum support monstr
2009-03-18 20:30 ` [PATCH 19/57] microblaze_v7: early_printk support monstr
2009-03-18 20:30 ` [PATCH 20/57] microblaze_v7: uaccess files monstr
2009-03-18 20:30 ` [PATCH 21/57] microblaze_v7: heartbeat file monstr
2009-03-18 20:30 ` [PATCH 22/57] microblaze_v7: setup.c, setup.h - system setting monstr
2009-03-18 20:30 ` [PATCH 23/57] microblaze_v7: asm-offsets monstr
2009-03-18 20:30 ` [PATCH 24/57] microblaze_v7: process and init task function monstr
2009-03-18 20:30 ` [PATCH 25/57] microblaze_v7: delay.h, timex.h monstr
2009-03-18 20:30 ` [PATCH 26/57] microblaze_v7: ptrace support monstr
2009-03-18 20:30 ` [PATCH 27/57] microblaze_v7: IPC support monstr
2009-03-18 20:30 ` [PATCH 28/57] microblaze_v7: traps support monstr
2009-03-18 20:30 ` [PATCH 29/57] microblaze_v7: memory inicialization, MMU, TLB monstr
2009-03-18 20:30 ` [PATCH 30/57] microblaze_v7: page.h, segment.h, unaligned.h monstr
2009-03-18 20:30 ` [PATCH 31/57] microblaze_v7: includes SHM*, msgbuf monstr
2009-03-18 20:30 ` [PATCH 32/57] microblaze_v7: bug headers files monstr
2009-03-18 20:31 ` [PATCH 33/57] microblaze_v7: definitions of types monstr
2009-03-18 20:31 ` [PATCH 34/57] microblaze_v7: ioctl support monstr
2009-03-18 20:31 ` [PATCH 35/57] microblaze_v7: io.h IO operations monstr
2009-03-18 20:31 ` [PATCH 36/57] microblaze_v7: headers for executables format FLAT, ELF monstr
2009-03-18 20:31 ` [PATCH 37/57] microblaze_v7: dma support monstr
2009-03-18 20:31 ` [PATCH 38/57] microblaze_v7: headers for irq monstr
2009-03-18 20:31 ` [PATCH 39/57] microblaze_v7: atomic.h bitops.h swab.h byteorder.h monstr
2009-03-18 20:31 ` [PATCH 40/57] microblaze_v7: headers pgalloc.h pgtable.h monstr
2009-03-18 20:31 ` [PATCH 41/57] microblaze_v7: system.h processor.h monstr
2009-03-18 20:31 ` [PATCH 42/57] microblaze_v7: clinkage.h linkage.h sections.h kmap_types.h monstr
2009-03-18 20:31 ` [PATCH 43/57] microblaze_v7: stats headers monstr
2009-03-18 20:31 ` [PATCH 44/57] microblaze_v7: termbits.h termios.h monstr
2009-03-23 19:37 ` Arnd Bergmann
2009-03-24 11:20 ` Michal Simek
2009-03-24 13:57 ` Arnd Bergmann
2009-03-24 14:06 ` John Williams
2009-03-24 14:44 ` Michal Simek
2009-03-18 20:31 ` [PATCH 45/57] microblaze_v7: sigcontext.h siginfo.h monstr
2009-03-18 20:31 ` [PATCH 46/57] microblaze_v7: headers simple files - empty or redirect to asm-generic monstr
2009-03-18 20:31 ` [PATCH 47/57] microblaze_v7: namei.h monstr
2009-03-18 20:31 ` [PATCH 48/57] microblaze_v7: headers files entry.h current.h mman.h registers.h sembuf.h monstr
2009-03-18 20:31 ` [PATCH 49/57] microblaze_v7: device.h param.h topology.h monstr
2009-03-18 20:31 ` [PATCH 50/57] microblaze_v7: pool.h socket.h monstr
2009-03-18 20:31 ` [PATCH 51/57] microblaze_v7: fcntl.h sockios.h ucontext.h monstr
2009-03-18 20:31 ` [PATCH 52/57] microblaze_v7: unistd.h monstr
2009-03-18 20:31 ` [PATCH 53/57] microblaze_v7: string.h thread_info.h monstr
2009-03-18 20:31 ` [PATCH 54/57] microblaze_v7: Kbuild file monstr
2009-03-18 20:31 ` [PATCH 55/57] microblaze_v7: pci headers monstr
2009-03-18 20:31 ` [PATCH 56/57] microblaze_v7: syscalls.h monstr
2009-03-18 20:31 ` [PATCH 57/57] microblaze_v7: Uartlite for Microblaze monstr
2009-03-24 16:03 ` Michal Simek
2009-03-24 16:22 ` John Williams
2009-03-24 16:47 ` Peter Korsgaard
2009-03-25 15:42 ` [PATCH 01/57] microblaze_v7: Kconfig patches Arnd Bergmann
2009-03-25 16:10 ` Michal Simek
2009-03-19 7:22 ` Microblaze linux support Ingo Molnar
2009-03-19 9:42 ` Michal Simek
2009-03-19 10:21 ` Ingo Molnar
2009-03-19 10:26 ` Michal Simek
2009-03-19 10:47 ` Jaswinder Singh Rajput
2009-03-19 11:10 ` Michal Simek
2009-03-19 10:50 ` Ingo Molnar
2009-03-19 10:52 ` Michal Simek
2009-03-19 11:00 ` Ingo Molnar
2009-03-19 11:04 ` Michal Simek
2009-03-19 20:35 ` Randy Dunlap
2009-03-19 20:41 ` Michal Simek
2009-03-24 15:26 ` Michal Simek
2009-03-24 15:33 ` John Linn
2009-03-24 15:42 ` Michal Simek
2009-03-24 17:46 ` [microblaze-uclinux] " Stephen Neuendorffer
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=49C4C3BD.9090905@monstr.eu \
--to=monstr@monstr.eu \
--cc=john.williams@petalogix.com \
--cc=johnstul@us.ibm.com \
--cc=linux-kernel@vger.kernel.org \
--cc=tglx@linutronix.de \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox