Filter:   InfoImg
download clocksource.h
Language: C
LOC: 65
Project Info
linux kernel
Server: Kernel.org
Type: zip
...linux kernel\include\linux\
   8250_pci.h
   a.out.h
   ac97_codec.h
   acct.h
   acpi.h
   adb.h
   adfs_fs.h
   adfs_fs_i.h
   adfs_fs_sb.h
   aer.h
   affs_hardblocks.h
   agp_backend.h
   agpgart.h
   aio.h
   aio_abi.h
   amifd.h
   amifdreg.h
   amigaffs.h
   apm_bios.h
   arcdevice.h
   arcfb.h
   ata.h
   atalk.h
   atm.h
   atm_eni.h
   atm_he.h
   atm_idt77105.h
   atm_nicstar.h
   atm_suni.h
   atm_tcp.h
   atm_zatm.h
   atmapi.h
   atmarp.h
   atmbr2684.h
   atmclip.h
   atmdev.h
   atmioc.h
   atmlec.h
   atmmpc.h
   atmppp.h
   atmsap.h
   atmsvc.h
   attribute_container.h
   audit.h
   auto_fs.h
   auto_fs4.h
   auxvec.h
   awe_voice.h
   ax25.h
   b1lli.h
   b1pcmcia.h
   backing-dev.h
   backlight.h
   baycom.h
   bcd.h
   bfs_fs.h
   binfmts.h
   bio.h
   bit_spinlock.h
   bitmap.h
   bitops.h
   blkdev.h
   blkpg.h
   blktrace_api.h
   blockgroup_lock.h
   bootmem.h
   bpqether.h
   buffer_head.h
   cache.h
   calc64.h
   capability.h
   capi.h
   carta_random32.h
   cciss_ioctl.h
   cd1400.h
   cdev.h
   cdk.h
   cdrom.h
   chio.h
   circ_buf.h
   clk.h
   clocksource.h
   cm4000_cs.h
   cn_proc.h
   cobalt-nvram.h
   coda.h
   coda_cache.h
   coda_fs_i.h
   coda_linux.h
   coda_proc.h
   coda_psdev.h
   coff.h
   com20020.h
   compat.h
   compat_ioctl.h
   compiler-gcc.h
   compiler-gcc3.h
   compiler-gcc4.h
   compiler-intel.h
   compiler.h
   completion.h
   comstats.h
   concap.h
   configfs.h
   connector.h
   console.h
   console_struct.h
   consolemap.h
   cpu.h
   cpufreq.h
   cpumask.h
   cpuset.h
   cramfs_fs.h
   cramfs_fs_sb.h
   crash_dump.h
   crc-ccitt.h
   crc16.h
   crc32.h
   crc32c.h
   crypto.h
   cryptohash.h
   ctype.h
   cuda.h
   cyclades.h
   cyclomx.h
   cycx_cfm.h
   cycx_drv.h
   cycx_x25.h
   dcache.h
   dccp.h
   dcookies.h
   debug_locks.h
   debugfs.h
   delay.h
   delayacct.h
   device-mapper.h
   device.h
   devpts_fs.h
   dio.h
   dirent.h
   divert.h
   dlm.h
   dlm_device.h
   dm-ioctl.h
   dm9000.h
   dma-mapping.h
   dmaengine.h
   dmapool.h
   dmi.h
   dn.h
   dnotify.h
   dqblk_v1.h
   dqblk_v2.h
   dqblk_xfs.h
   ds1286.h
   ds17287rtc.h
   ds1742rtc.h
   dtlk.h
   edd.h
   efi.h
   efs_dir.h
   efs_fs.h
   efs_fs_i.h
   efs_fs_sb.h
   efs_vh.h
   eisa.h
   elevator.h
   elf-em.h
   elf-fdpic.h
   elf.h
   elfcore.h
   elfnote.h
   err.h
   errno.h
   errqueue.h
   etherdevice.h
   ethtool.h
   eventpoll.h
   ext2_fs.h
   ext2_fs_sb.h
   ext3_fs.h
   ext3_fs_i.h
   ext3_fs_sb.h
   ext3_jbd.h
   ext4_fs.h
   ext4_fs_extents.h
   ext4_fs_i.h
   ext4_fs_sb.h
   ext4_jbd2.h
   fadvise.h
   fb.h
   fcdevice.h
   fcntl.h
   fd.h
   fd1772.h
   fddidevice.h
   fdreg.h
   fib_rules.h
   file.h
   filter.h
   firmware.h
   flat.h
   font.h
   fs.h
   fs_enet_pd.h
   fs_struct.h
   fs_uart_pd.h
   fsl_devices.h
   fsnotify.h
   ftape-header-segment.h
   ftape-vendors.h
   ftape.h
   fuse.h
   futex.h
   gameport.h
   gen_stats.h
   genalloc.h
   generic_acl.h
   generic_serial.h
   genetlink.h
   genhd.h
   getcpu.h
   gfp.h
   gfs2_ondisk.h
   gigaset_dev.h
   hardirq.h
   harrier_defs.h
   hash.h
   hayesesp.h
   hdlc.h
   hdlcdrv.h
   hdpu_features.h
   hdreg.h
   hdsmart.h
   hiddev.h
   highmem.h
   highuid.h
   hil.h
   hil_mlc.h
   hippidevice.h
   hp_sdc.h
   hpet.h
   hrtimer.h
   htirq.h
   hugetlb.h
   hw_random.h
   hwmon-sysfs.h
   hwmon-vid.h
   hwmon.h
   hysdn_if.h
   i2c-algo-bit.h
   i2c-algo-ite.h
   i2c-algo-pca.h
   i2c-algo-pcf.h
   i2c-algo-sgi.h
   i2c-dev.h
   i2c-id.h
   i2c-isa.h
   i2c-ocores.h
   i2c-pxa.h
   i2c.h
   i2o-dev.h
   i2o.h
   i8k.h
   ibmtr.h
   icmp.h
   icmpv6.h
   ide.h
   idr.h
   if.h
   if_addr.h
   if_arcnet.h
   if_arp.h
   if_bonding.h
   if_bridge.h
   if_cablemodem.h
   if_ec.h
   if_eql.h
   if_ether.h
   if_fc.h
   if_fddi.h
   if_frad.h
   if_hippi.h
   if_infiniband.h
   if_link.h
   if_ltalk.h
   if_packet.h
   if_plip.h
   if_ppp.h
   if_pppox.h
   if_shaper.h
   if_slip.h
   if_strip.h
   if_tr.h
   if_tun.h
   if_tunnel.h
   if_vlan.h
   if_wanpipe.h
   if_wanpipe_common.h
   igmp.h
   in.h
   in_route.h
   in6.h
   inet.h
   inet_diag.h
   inetdevice.h
   init.h
   init_task.h
   initrd.h
   inotify.h
   input.h
   interrupt.h
   io.h
   ioc3.h
   ioc4.h
   ioctl.h
   ioctl32.h
   ioport.h
   ioprio.h
   ip.h
   ip_mp_alg.h
   ip6_tunnel.h
   ipc.h
   ipmi.h
   ipmi_msgdefs.h
   ipmi_smi.h
   ipsec.h
   ipv6.h
   ipv6_route.h
   ipx.h
   irda.h
   irq.h
   irq_cpustat.h
   irqflags.h
   irqreturn.h
   isa.h
   isapnp.h
   isdn.h
   isdn_divertif.h
   isdn_ppp.h
   isdnif.h
   isicom.h
   iso_fs.h
   istallion.h
   ixjuser.h
   jbd.h
   jbd2.h
   jffs.h
   jffs2.h
   jhash.h
   jiffies.h
   journal-head.h
   joystick.h
   kallsyms.h
   kbd_diacr.h
   kbd_kern.h
   kd.h
   kdev_t.h
   kernel.h
   kernel_stat.h
   kernelcapi.h
   kexec.h
   key-ui.h
   key.h
   keyboard.h
   keyctl.h
   kfifo.h
   klist.h
   kmalloc_sizes.h
   kmod.h
   kobj_map.h
   kobject.h
   kprobes.h
   kref.h
   kthread.h
   ktime.h
   lapb.h
   latency.h
   lcd.h
   leds.h
   libata.h
   libps2.h
   license.h
   limits.h
   linkage.h
   linux_logo.h
   list.h
   llc.h
   lm_interface.h
   lock_dlm_plock.h
   lockdep.h
   loop.h
   lp.h
   m41t00.h
   m48t86.h
   magic.h
   major.h
   matroxfb.h
   mbcache.h
   mc146818rtc.h
   mc6821.h
   mca-legacy.h
   mca.h
   memory.h
   memory_hotplug.h
   mempolicy.h
   mempool.h
   meye.h
   migrate.h
   mii.h
   minix_fs.h
   miscdevice.h
   mm.h
   mm_inline.h
   mm_types.h
   mman.h
   mmtimer.h
   mmzone.h
   mod_devicetable.h
   module.h
   moduleloader.h
   moduleparam.h
   mount.h
   mpage.h
   mqueue.h
   mroute.h
   msdos_fs.h
   msg.h
   msi.h
   mtio.h
   mutex-debug.h
   mutex.h
   mv643xx.h
   n_r3964.h
   namei.h
   namespace.h
   nbd.h
   ncp.h
   ncp_fs.h
   ncp_fs_i.h
   ncp_fs_sb.h
   ncp_mount.h
   ncp_no.h
   neighbour.h
   net.h
   netdevice.h
   netfilter.h
   netfilter_arp.h
   netfilter_bridge.h
   netfilter_decnet.h
   netfilter_ipv4.h
   netfilter_ipv6.h
   netlink.h
   netpoll.h
   netrom.h
   nfs.h
   nfs_fs.h
   nfs_fs_i.h
   nfs_fs_sb.h
   nfs_idmap.h
   nfs_mount.h
   nfs_page.h
   nfs_xdr.h
   nfs2.h
   nfs3.h
   nfs4.h
   nfs4_acl.h
   nfs4_mount.h
   nfsacl.h
   nfsd_idmap.h
   nls.h
   nmi.h
   node.h
   nodemask.h
   notifier.h
   nsc_gpio.h
   nsproxy.h
   nubus.h
   numa.h
   nvram.h
   oom.h
   oprofile.h
   page-flags.h
   pagemap.h
   pagevec.h
   param.h
   parport.h
   parport_pc.h
   parser.h
   patchkey.h
   pci-acpi.h
   pci.h
   pci_hotplug.h
   pci_ids.h
   pci_regs.h
   pcieport_if.h
   percpu.h
   percpu_counter.h
   personality.h
   pfkeyv2.h
   pfn.h
   pg.h
   phonedev.h
   phy.h
   pid.h
   pipe_fs_i.h
   pkt_cls.h
   pkt_sched.h
   pktcdvd.h
   platform_device.h
   plist.h
   pm.h
   pm_legacy.h
   pmu.h
   pnp.h
   pnpbios.h
   poison.h
   poll.h
   posix-timers.h
   posix_acl.h
   posix_acl_xattr.h
   posix_types.h
   ppdev.h
   ppp-comp.h
   ppp_channel.h
   ppp_defs.h
   prctl.h
   preempt.h
   prefetch.h
   prio_tree.h
   proc_fs.h
   profile.h
   ps2esdi.h
   pspace.h
   ptrace.h
   qic117.h
   qnx4_fs.h
   qnxtypes.h
   quota.h
   quotaio_v1.h
   quotaio_v2.h
   quotaops.h
   radeonfb.h
   radix-tree.h
   raid_class.h
   ramfs.h
   random.h
   raw.h
   rbtree.h
   rcupdate.h
   reboot.h
   reboot_fixups.h
   reiserfs_acl.h
   reiserfs_fs.h
   reiserfs_fs_i.h
   reiserfs_fs_sb.h
   reiserfs_xattr.h
   relay.h
   resource.h
   resume-trace.h
   rio.h
   rio_drv.h
   rio_ids.h
   rio_regs.h
   rmap.h
   romfs_fs.h
   root_dev.h
   rose.h
   route.h
   rslib.h
   rtc-v3020.h
   rtc.h
   rtmutex.h
   rtnetlink.h
   rwsem-spinlock.h
   rwsem.h
   sc26198.h
   scatterlist.h
   scc.h
   sched.h
   screen_info.h
   sctp.h
   scx200.h
   scx200_gpio.h
   sdla.h
   sdla_fr.h
   seccomp.h
   securebits.h
   security.h
   selection.h
   selinux.h
   selinux_netlink.h
   sem.h
   seq_file.h
   seqlock.h
   serial.h
   serial_8250.h
   serial_core.h
   serial_ip3106.h
   serial_reg.h
   serial167.h
   serialP.h
   serio.h
   shm.h
   shmem_fs.h
   signal.h
   skbuff.h
   slab.h
   smb.h
   smb_fs.h
   smb_fs_i.h
   smb_fs_sb.h
   smb_mount.h
   smbno.h
   smp.h
   smp_lock.h
   snmp.h
   socket.h
   sockios.h
   som.h
   sonet.h
   sonypi.h
   sort.h
   sound.h
   soundcard.h
   spinlock.h
   spinlock_api_smp.h
   spinlock_api_up.h
   spinlock_types.h
   spinlock_types_up.h
   spinlock_up.h
   srcu.h
   stacktrace.h
   stallion.h
   stat.h
   statfs.h
   stddef.h
   stop_machine.h
   string.h
   stringify.h
   superhyway.h
   suspend.h
   swap.h
   swapops.h
   synclink.h
   sys.h
   syscalls.h
   sysctl.h
   sysdev.h
   sysfs.h
   sysrq.h
   sysv_fs.h
   taskstats.h
   taskstats_kern.h
   tcp.h
   telephony.h
   termios.h
   textsearch.h
   textsearch_fsm.h
   tfrc.h
   thread_info.h
   threads.h
   ticable.h
   tifm.h
   time.h
   timer.h
   times.h
   timex.h
   tiocl.h
   tipc.h
   tipc_config.h
   topology.h
   toshiba.h
   transport_class.h
   trdevice.h
   tsacct_kern.h
   tty.h
   tty_driver.h
   tty_flip.h
   tty_ldisc.h
   types.h
   uaccess.h
   udf_fs.h
   udf_fs_i.h
   udf_fs_sb.h
   udp.h
   ufs_fs.h
   ufs_fs_i.h
   ufs_fs_sb.h
   uinput.h
   uio.h
   ultrasound.h
   umem.h
   un.h
   unistd.h
   unwind.h
   usb.h
   usb_ch9.h
   usb_gadget.h
   usb_gadgetfs.h
   usb_usual.h
   usbdevice_fs.h
   user.h
   utime.h
   uts.h
   utsname.h
   vermagic.h
   vfs.h
   via.h
   video_decoder.h
   video_encoder.h
   videodev.h
   videodev2.h
   videotext.h
   vmalloc.h
   vmstat.h
   vt.h
   vt_buffer.h
   vt_kern.h
   wait.h
   wanrouter.h
   watchdog.h
   wireless.h
   workqueue.h
   writeback.h
   x25.h
   xattr.h
   xfrm.h
   yam.h
   zconf.h
   zftape.h
   zlib.h
   zorro.h
   zorro_ids.h
   zutil.h

/*  linux/include/linux/clocksource.h
 *
 *  This file contains the structure definitions for clocksources.
 *
 *  If you are not a clocksource, or timekeeping code, you should
 *  not be including this file!
 */
#ifndef _LINUX_CLOCKSOURCE_H
#define _LINUX_CLOCKSOURCE_H

#include <linux/types.h>
#include <linux/timex.h>
#include <linux/time.h>
#include <linux/list.h>
#include <asm/div64.h>
#include <asm/io.h>

/* clocksource cycle base type */
typedef u64 cycle_t;

/**
 * struct clocksource - hardware abstraction for a free running counter
 *	Provides mostly state-free accessors to the underlying hardware.
 *
 * @name:		ptr to clocksource name
 * @list:		list head for registration
 * @rating:		rating value for selection (higher is better)
 *			To avoid rating inflation the following
 *			list should give you a guide as to how
 *			to assign your clocksource a rating
 *			1-99: Unfit for real use
 *				Only available for bootup and testing purposes.
 *			100-199: Base level usability.
 *				Functional for real use, but not desired.
 *			200-299: Good.
 *				A correct and usable clocksource.
 *			300-399: Desired.
 *				A reasonably fast and accurate clocksource.
 *			400-499: Perfect
 *				The ideal clocksource. A must-use where
 *				available.
 * @read:		returns a cycle value
 * @mask:		bitmask for two's complement
 *			subtraction of non 64 bit counters
 * @mult:		cycle to nanosecond multiplier
 * @shift:		cycle to nanosecond divisor (power of two)
 * @update_callback:	called when safe to alter clocksource values
 * @is_continuous:	defines if clocksource is free-running.
 * @cycle_interval:	Used internally by timekeeping core, please ignore.
 * @xtime_interval:	Used internally by timekeeping core, please ignore.
 */
struct clocksource {
	char *name;
	struct list_head list;
	int rating;
	cycle_t (*read)(void);
	cycle_t mask;
	u32 mult;
	u32 shift;
	int (*update_callback)(void);
	int is_continuous;

	/* timekeeping specific data, ignore */
	cycle_t cycle_last, cycle_interval;
	u64 xtime_nsec, xtime_interval;
	s64 error;
};

/* simplify initialization of mask field */
#define CLOCKSOURCE_MASK(bits) (cycle_t)(bits<64 ? ((1ULL<<bits)-1) : -1)

/**
 * clocksource_khz2mult - calculates mult from khz and shift
 * @khz:		Clocksource frequency in KHz
 * @shift_constant:	Clocksource shift factor
 *
 * Helper functions that converts a khz counter frequency to a timsource
 * multiplier, given the clocksource shift value
 */
static inline u32 clocksource_khz2mult(u32 khz, u32 shift_constant)
{
	/*  khz = cyc/(Million ns)
	 *  mult/2^shift  = ns/cyc
	 *  mult = ns/cyc * 2^shift
	 *  mult = 1Million/khz * 2^shift
	 *  mult = 1000000 * 2^shift / khz
	 *  mult = (1000000<<shift) / khz
	 */
	u64 tmp = ((u64)1000000) << shift_constant;

	tmp += khz/2; /* round for do_div */
	do_div(tmp, khz);

	return (u32)tmp;
}

/**
 * clocksource_hz2mult - calculates mult from hz and shift
 * @hz:			Clocksource frequency in Hz
 * @shift_constant:	Clocksource shift factor
 *
 * Helper functions that converts a hz counter
 * frequency to a timsource multiplier, given the
 * clocksource shift value
 */
static inline u32 clocksource_hz2mult(u32 hz, u32 shift_constant)
{
	/*  hz = cyc/(Billion ns)
	 *  mult/2^shift  = ns/cyc
	 *  mult = ns/cyc * 2^shift
	 *  mult = 1Billion/hz * 2^shift
	 *  mult = 1000000000 * 2^shift / hz
	 *  mult = (1000000000<<shift) / hz
	 */
	u64 tmp = ((u64)1000000000) << shift_constant;

	tmp += hz/2; /* round for do_div */
	do_div(tmp, hz);

	return (u32)tmp;
}

/**
 * clocksource_read: - Access the clocksource's current cycle value
 * @cs:		pointer to clocksource being read
 *
 * Uses the clocksource to return the current cycle_t value
 */
static inline cycle_t clocksource_read(struct clocksource *cs)
{
	return cs->read();
}

/**
 * cyc2ns - converts clocksource cycles to nanoseconds
 * @cs:		Pointer to clocksource
 * @cycles:	Cycles
 *
 * Uses the clocksource and ntp ajdustment to convert cycle_ts to nanoseconds.
 *
 * XXX - This could use some mult_lxl_ll() asm optimization
 */
static inline s64 cyc2ns(struct clocksource *cs, cycle_t cycles)
{
	u64 ret = (u64)cycles;
	ret = (ret * cs->mult) >> cs->shift;
	return ret;
}

/**
 * clocksource_calculate_interval - Calculates a clocksource interval struct
 *
 * @c:		Pointer to clocksource.
 * @length_nsec: Desired interval length in nanoseconds.
 *
 * Calculates a fixed cycle/nsec interval for a given clocksource/adjustment
 * pair and interval request.
 *
 * Unless you're the timekeeping code, you should not be using this!
 */
static inline void clocksource_calculate_interval(struct clocksource *c,
						unsigned long length_nsec)
{
	u64 tmp;

	/* XXX - All of this could use a whole lot of optimization */
	tmp = length_nsec;
	tmp <<= c->shift;
	tmp += c->mult/2;
	do_div(tmp, c->mult);

	c->cycle_interval = (cycle_t)tmp;
	if (c->cycle_interval == 0)
		c->cycle_interval = 1;

	c->xtime_interval = (u64)c->cycle_interval * c->mult;
}


/* used to install a new clocksource */
int clocksource_register(struct clocksource*);
void clocksource_reselect(void);
struct clocksource* clocksource_get_next(void);

#endif /* _LINUX_CLOCKSOURCE_H */