time: Tree wide cleanup of interfaces and crap
Subsystems (14)
PATCH 2/13 tsacct: Use ktime_get_ts()
In reply to Thomas Gleixnerdo_posix_clock_monotonic_gettime() is a leftover from the initial posix timer implementation which maps to ktime_get_ts()
--- kernel/tsacct.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/tsacct.c +1 -1
@@ -38,7 +38,7 @@ void bacct_add_tsk(struct user_namespaceBUILD_BUG_ON (TS_COMM_LEN <TASK_COMM_LEN );/* calculate task elapsed time in timespec */ -do_posix_clock_monotonic_gettime (&uptime); +ktime_get_ts (&uptime); ts =timespec_sub (uptime, tsk->start_time);/* rebase elapsed time to usec (should never be negative) */ ac_etime =timespec_to_ns (&ts);
PATCH 1/13 acct: Use ktime_get_ts()
In reply to Thomas Gleixnerdo_posix_clock_monotonic_gettime() is a leftover from the initial posix timer implementation which maps to ktime_get_ts()
--- kernel/acct.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/acct.c +1 -1
@@ -484,7 +484,7 @@ static void do_acct_process(struct bsd_astrlcpy (ac.ac_comm, current->comm,sizeof (ac.ac_comm));/* calculate run_time in nsec*/ -do_posix_clock_monotonic_gettime (&uptime); +ktime_get_ts (&uptime); run_time = (u64 )uptime.tv_sec*NSEC_PER_SEC + uptime.tv_nsec; run_time -= (u64 )current->group_leader->start_time.tv_sec *NSEC_PER_SEC + current->group_leader->start_time.tv_nsec;
cover time: Tree wide cleanup of interfaces and crap
This is part 1 of a larger cleanup series I have on store. This just deals with simple independent cleanups, except for the removal of do_posix_clock_monotonic_gettime() which depends on all the related cleanup patches being applied. I'm happy to take the whole series trough my tree if nobody objects.
1) Finally get rid of do_posix_clock_monotonic_gettime() which is just a wrapper around ktime_get_ts()
2) Kill a few braindamaged time conversion sites
Thanks,
tglx
----
drivers/firewire/core-cdev.c | 2 +- drivers/net/wireless/mwifiex/cfg80211.c | 4 +--- drivers/net/wireless/mwifiex/main.c | 4 +--- drivers/net/wireless/mwifiex/tdls.c | 6 ++---- drivers/net/wireless/mwifiex/uap_txrx.c | 4 +--- drivers/net/wireless/mwifiex/wmm.c | 9 +-------- include/linux/time.h | 1 - include/sound/pcm.h | 2 +- kernel/acct.c | 2 +- kernel/debug/kdb/kdb_main.c | 2 +- kernel/delayacct.c | 16 +++------------- kernel/fork.c | 2 +- kernel/tsacct.c | 2 +- net/mac80211/cfg.c | 2 +- net/mac80211/debugfs_sta.c | 2 +- net/mac80211/sta_info.c | 2 +- net/mac80211/status.c | 7 ++----- net/mac80211/tx.c | 5 +---- security/tomoyo/audit.c | 8 +++----- security/tomoyo/common.c | 4 +--- sound/core/timer.c | 4 ++-- sound/pci/intel8x0.c | 10 ++++------ 22 files changed, 31 insertions(+), 69 deletions(-)
PATCH 3/13 delayacct: Use ktime_get_ts()
do_posix_clock_monotonic_gettime() is a leftover from the initial posix timer implementation which maps to ktime_get_ts(). Remove the silly wrapper while at it.
--- kernel/delayacct.c | 16 +++------------- 1 file changed, 3 insertions(+), 13 deletions(-)
kernel/delayacct.c +3 -13
@@ -46,16 +46,6 @@ void __delayacct_tsk_init(struct task_st }/* -* Start accounting for a delay statistic using -* its starting timestamp (@start) -*/ - -static inline void delayacct_start (struct timespec *start) -{ -do_posix_clock_monotonic_gettime (start); -} - -/* * Finish delay accounting for a statistic using * its timestamps (@start, @end), accumalator (@total) and @count */
@@ -67,7 +57,7 @@ static void delayacct_end(struct timespes64 ns;unsigned long flags; -do_posix_clock_monotonic_gettime (end); +ktime_get_ts (end); ts =timespec_sub (*end, *start); ns =timespec_to_ns (&ts);if (ns <0 )
@@ -81,7 +71,7 @@ static void delayacct_end(struct timespevoid __delayacct_blkio_start (void ) { -delayacct_start (¤t->delays->blkio_start); +ktime_get_ts (¤t->delays->blkio_start); }void __delayacct_blkio_end (void )
@@ -169,7 +159,7 @@ __u64 __delayacct_blkio_ticks(struct tasvoid __delayacct_freepages_start (void ) { -delayacct_start (¤t->delays->freepages_start); +ktime_get_ts (¤t->delays->freepages_start); }void __delayacct_freepages_end (void )
PATCH 10/13 time: Remove do_posix_clock_monotonic_gettime()
In reply to Thomas Gleixnerdo_posix_clock_monotonic_gettime() is a leftover from the initial posix timer implementation which maps to ktime_get_ts().
No more users. Remove the cruft.
--- include/linux/time.h | 1 - 1 file changed, 1 deletion(-)
include/linux/time.h +0 -1
@@ -157,7 +157,6 @@ extern void do_gettimeofday(struct timevextern int do_settimeofday (const struct timespec *tv);extern int do_sys_settimeofday (const struct timespec *tv,const struct timezone *tz); -#define do_posix_clock_monotonic_gettime (ts) ktime_get_ts(ts)extern long do_utimes (int dfd,const char __user *filename,struct timespec *times,int flags);struct itimerval ; extern int do_setitimer(int which, struct itimerval *value,
PATCH 13/13 tomoyo: Use sensible time interface
In reply to Thomas GleixnerThere is no point in calling gettimeofday if only the seconds part of the timespec is used. Use get_seconds() instead. It's not only the proper interface it's also faster.
--- security/tomoyo/audit.c | 8 +++----- security/tomoyo/common.c | 4 +--- 2 files changed, 4 insertions(+), 8 deletions(-)
security/tomoyo/audit.c +3 -5
@@ -155,11 +155,9 @@ static char *tomoyo_print_header(structu8 i;if (!buffer)return NULL ; - { -struct timeval tv; -do_gettimeofday (&tv); -tomoyo_convert_time (tv.tv_sec, &stamp); - } + +tomoyo_convert_time (get_seconds (), &stamp); + pos =snprintf (buffer, tomoyo_buffer_len -1 ,"#%04u/%02u/%02u %02u:%02u:%02u# profile=%u mode=%s " "granted=%s (global-pid=%u) task={ pid=%u ppid=%u "
security/tomoyo/common.c +1 -3
@@ -2267,13 +2267,11 @@ static unsigned int tomoyo_stat_modified*/ void tomoyo_update_stat (const u8 index) { -struct timeval tv; -do_gettimeofday (&tv);/* * I don't use atomic operations because race condition is not fatal. */ tomoyo_stat_updated[index]++; - tomoyo_stat_modified[index] = tv.tv_sec; + tomoyo_stat_modified[index] =get_seconds (); }/**
PATCH 4/13 net: mac80211: Use ktime_get_ts()
In reply to Thomas Gleixnerdo_posix_clock_monotonic_gettime() is a leftover from the initial posix timer implementation which maps to ktime_get_ts().
--- net/mac80211/cfg.c | 2 +- net/mac80211/debugfs_sta.c | 2 +- net/mac80211/sta_info.c | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-)
net/mac80211/cfg.c +1 -1
@@ -484,7 +484,7 @@ static void sta_set_sinfo(struct sta_infSTATION_INFO_STA_FLAGS |STATION_INFO_BEACON_LOSS_COUNT ; -do_posix_clock_monotonic_gettime (&uptime); +ktime_get_ts (&uptime); sinfo->connected_time = uptime.tv_sec - sta->last_connected; sinfo->inactive_time =jiffies_to_msecs (jiffies - sta->last_rx);
net/mac80211/debugfs_sta.c +1 -1
@@ -124,7 +124,7 @@ static ssize_t sta_connected_time_read(slong connected_time_secs;char buf[100 ];int res; -do_posix_clock_monotonic_gettime (&uptime); +ktime_get_ts (&uptime); connected_time_secs = uptime.tv_sec - sta->last_connected;time_to_tm (connected_time_secs,0 , &result); result.tm_year -=70 ;
net/mac80211/sta_info.c +1 -1
@@ -357,7 +357,7 @@ struct sta_info *sta_info_alloc(struct i sta->sta_state =IEEE80211_STA_NONE ; -do_posix_clock_monotonic_gettime (&uptime); +ktime_get_ts (&uptime); sta->last_connected = uptime.tv_sec;ewma_init (&sta->avg_signal,1024 ,8 );for (i =0 ; i <ARRAY_SIZE (sta->chain_signal_avg); i++)
PATCH 12/13 net: mac80211: Remove silly timespec dance
In reply to Thomas GleixnerConverting time from one format to another seems to give coders a warm and fuzzy feeling.
Use the proper interfaces.
--- net/mac80211/status.c | 7 ++----- net/mac80211/tx.c | 5 +---- 2 files changed, 3 insertions(+), 9 deletions(-)
net/mac80211/status.c +2 -5
@@ -473,8 +473,6 @@ static void ieee80211_tx_latency_end_msrstruct sta_info *sta, struct ieee80211_hdr *hdr) { - ktime_t skb_dprt; -struct timespec dprt_time; u32 msrmnt;u16 tid;u8 *qc;
@@ -506,9 +504,8 @@ static void ieee80211_tx_latency_end_msr tx_lat = &sta->tx_lat[tid]; -ktime_get_ts (&dprt_time);/* time stamp completion time */ - skb_dprt =ktime_set (dprt_time.tv_sec, dprt_time.tv_nsec); - msrmnt =ktime_to_ms (ktime_sub (skb_dprt, skb_arv)); +/* Calculate the latency */ + msrmnt =ktime_to_ms (net_timedelta (skb_arv));if (tx_lat->max < msrmnt)/* update stats */ tx_lat->max = msrmnt;
net/mac80211/tx.c +1 -4
@@ -1767,15 +1767,12 @@ fail:static void ieee80211_tx_latency_start_msrmnt (struct ieee80211_local *local,struct sk_buff *skb) { -struct timespec skb_arv;struct ieee80211_tx_latency_bin_ranges *tx_latency; tx_latency =rcu_dereference (local->tx_latency);if (!tx_latency)return ; - -ktime_get_ts (&skb_arv); - skb->tstamp =ktime_set (skb_arv.tv_sec, skb_arv.tv_nsec); +__net_timestamp (skb); }/**
PATCH 11/13 wireless: mwifiex: Use the proper interfaces
In reply to Thomas GleixnerWhy is converting time formats so desired if there are proper interfaces for this?
--- drivers/net/wireless/mwifiex/cfg80211.c | 4 +--- drivers/net/wireless/mwifiex/main.c | 4 +--- drivers/net/wireless/mwifiex/tdls.c | 6 ++---- drivers/net/wireless/mwifiex/uap_txrx.c | 4 +--- drivers/net/wireless/mwifiex/wmm.c | 9 +-------- 5 files changed, 6 insertions(+), 21 deletions(-)
drivers/net/wireless/mwifiex/cfg80211.c +1 -3
@@ -151,7 +151,6 @@ mwifiex_form_mgmt_frame(struct sk_buff *u8 addr[ETH_ALEN ] = {0xFF ,0xFF ,0xFF ,0xFF ,0xFF ,0xFF };u16 pkt_len;u32 tx_control =0 , pkt_type =PKT_TYPE_MGMT ; -struct timeval tv; pkt_len = len +ETH_ALEN ;
@@ -173,8 +172,7 @@ mwifiex_form_mgmt_frame(struct sk_buff * len - sizeof(struct ieee80211_hdr_3addr)); skb->priority =LOW_PRIO_TID ; -do_gettimeofday (&tv); - skb->tstamp =timeval_to_ktime (tv); +__net_timestamp (skb);return 0 ; }
drivers/net/wireless/mwifiex/main.c +1 -3
@@ -611,7 +611,6 @@ mwifiex_hard_start_xmit(struct sk_buff *struct mwifiex_private *priv =mwifiex_netdev_get_priv (dev);struct sk_buff *new_skb;struct mwifiex_txinfo *tx_info; -struct timeval tv;dev_dbg (priv->adapter->dev,"data: %lu BSS(%d-%d): Data <= kernel\n" , jiffies, priv->bss_type, priv->bss_num);
@@ -658,8 +657,7 @@ mwifiex_hard_start_xmit(struct sk_buff ** firmware for aggregate delay calculation for stats and * MSDU lifetime expiry. */ -do_gettimeofday (&tv); - skb->tstamp =timeval_to_ktime (tv); +__net_timestamp (skb);mwifiex_queue_tx_pkt (priv, skb);
drivers/net/wireless/mwifiex/tdls.c +2 -4
@@ -552,8 +552,7 @@ int mwifiex_send_tdls_data_frame(struct tx_info->bss_num = priv->bss_num; tx_info->bss_type = priv->bss_type; -do_gettimeofday (&tv); - skb->tstamp =timeval_to_ktime (tv); +__net_timestamp (skb);mwifiex_queue_tx_pkt (priv, skb);return 0 ;
@@ -710,8 +709,7 @@ int mwifiex_send_tdls_action_frame(struc pkt_len = skb->len -MWIFIEX_MGMT_FRAME_HEADER_SIZE -sizeof (pkt_len);memcpy (skb->data +MWIFIEX_MGMT_FRAME_HEADER_SIZE , &pkt_len,sizeof (pkt_len)); -do_gettimeofday (&tv); - skb->tstamp =timeval_to_ktime (tv); +__net_timestamp (skb);mwifiex_queue_tx_pkt (priv, skb);return 0 ;
drivers/net/wireless/mwifiex/uap_txrx.c +1 -3
@@ -96,7 +96,6 @@ static void mwifiex_uap_queue_bridged_pkstruct sk_buff *new_skb;struct mwifiex_txinfo *tx_info;int hdr_chop; -struct timeval tv;struct ethhdr *p_ethhdr; uap_rx_pd = (struct uap_rxpd *)(skb->data);
@@ -192,8 +191,7 @@ static void mwifiex_uap_queue_bridged_pk tx_info->pkt_len = skb->len; } -do_gettimeofday (&tv); - skb->tstamp =timeval_to_ktime (tv); +__net_timestamp (skb);mwifiex_wmm_add_buf_txqueue (priv, skb);atomic_inc (&adapter->tx_pending);atomic_inc (&adapter->pending_bridged_pkts);
drivers/net/wireless/mwifiex/wmm.c +1 -8
@@ -886,15 +886,8 @@ u8 mwifiex_wmm_compute_drv_pkt_delay(struct mwifiex_private *priv, const struct sk_buff *skb) { + u32 queue_delay = ktime_to_ms(net_timedelta(skb->tstamp));u8 ret_val; -struct timeval out_tstamp, in_tstamp; -u32 queue_delay; - -do_gettimeofday (&out_tstamp); - in_tstamp =ktime_to_timeval (skb->tstamp); - - queue_delay = (out_tstamp.tv_sec - in_tstamp.tv_sec) *1000 ; - queue_delay += (out_tstamp.tv_usec - in_tstamp.tv_usec) /1000 ;/* * Queue delay is passed as a uint8 in units of 2ms (ms shifted
PATCH 7/13 kdb: Use ktime_get_ts()
In reply to Thomas Gleixnerdo_posix_clock_monotonic_gettime() is a leftover from the initial posix timer implementation which maps to ktime_get_ts().
--- kernel/debug/kdb/kdb_main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/debug/kdb/kdb_main.c +1 -1
@@ -2472,7 +2472,7 @@ static void kdb_gmtime(struct timespec *static void kdb_sysinfo (struct sysinfo *val) {struct timespec uptime; -do_posix_clock_monotonic_gettime (&uptime); +ktime_get_ts (&uptime);memset (val,0 ,sizeof (*val)); val->uptime = uptime.tv_sec; val->loads[0 ] = avenrun[0 ];
PATCH 9/13 fork: Use ktime_get_ts()
In reply to Thomas Gleixnerdo_posix_clock_monotonic_gettime() is a leftover from the initial posix timer implementation which maps to ktime_get_ts().
--- kernel/fork.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/fork.c +1 -1
@@ -1262,7 +1262,7 @@ static struct task_struct *copy_process(posix_cpu_timers_init (p); -do_posix_clock_monotonic_gettime (&p->start_time); +ktime_get_ts (&p->start_time); p->real_start_time = p->start_time;monotonic_to_bootbased (&p->real_start_time); p->io_context =NULL ;
PATCH 8/13 firewire: Use ktime_get_ts()
In reply to Thomas Gleixnerdo_posix_clock_monotonic_gettime() is a leftover from the initial posix timer implementation which maps to ktime_get_ts()
--- drivers/firewire/core-cdev.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/firewire/core-cdev.c +1 -1
@@ -1215,7 +1215,7 @@ static int ioctl_get_cycle_timer2(structswitch (a->clk_id) {case CLOCK_REALTIME :getnstimeofday (&ts);break ; -case CLOCK_MONOTONIC :do_posix_clock_monotonic_gettime (&ts);break ; +case CLOCK_MONOTONIC :ktime_get_ts (&ts);break ;case CLOCK_MONOTONIC_RAW :getrawmonotonic (&ts);break ;default : ret = -EINVAL ;
PATCH 5/13 sound: Use ktime_get_ts()
In reply to Thomas Gleixnerdo_posix_clock_monotonic_gettime() is a leftover from the initial posix timer implementation which maps to ktime_get_ts().
--- include/sound/pcm.h | 2 +- sound/core/timer.c | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-)
include/sound/pcm.h +1 -1
@@ -932,7 +932,7 @@ static inline void snd_pcm_gettime(struc struct timespec *tv) {if (runtime->tstamp_type ==SNDRV_PCM_TSTAMP_TYPE_MONOTONIC ) -do_posix_clock_monotonic_gettime (tv); +ktime_get_ts (tv);else getnstimeofday (tv); }
sound/core/timer.c +2 -2
@@ -390,7 +390,7 @@ static void snd_timer_notify1(struct sndstruct timespec tstamp;if (timer_tstamp_monotonic) -do_posix_clock_monotonic_gettime (&tstamp); +ktime_get_ts (&tstamp);else getnstimeofday (&tstamp); if (snd_BUG_ON(event < SNDRV_TIMER_EVENT_START ||
@@ -1203,7 +1203,7 @@ static void snd_timer_user_tinterrupt(st }if (tu->last_resolution != resolution || ticks >0 ) {if (timer_tstamp_monotonic) -do_posix_clock_monotonic_gettime (&tstamp); +ktime_get_ts (&tstamp);else getnstimeofday (&tstamp); }
PATCH 6/13 sound: intel8x0: Use ktime and ktime_get()
In reply to Thomas Gleixnerdo_posix_clock_monotonic_gettime() is a leftover from the initial posix timer implementation which maps to ktime_get_ts() and returns the monotonic time in a timespec.
Use ktime based ktime_get() and use the ktime_delta_us() function to calculate the delta instead of open coding the timespec math.
--- sound/pci/intel8x0.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-)
sound/pci/intel8x0.c +4 -6
@@ -2779,7 +2779,7 @@ static void intel8x0_measure_ac97_clock(unsigned long port;unsigned long pos, pos1, t;int civ, timeout =1000 , attempt =1 ; -struct timespec start_time, stop_time; +ktime_t start_time, stop_time;if (chip->ac97_bus->clock !=48000 )return ;/* specified in module option */
@@ -2813,7 +2813,7 @@ static void intel8x0_measure_ac97_clock(iputbyte (chip, port +ICH_REG_OFF_CR ,ICH_IOCE );iputdword (chip,ICHREG (ALI_DMACR ),1 << ichdev->ali_slot); } -do_posix_clock_monotonic_gettime (&start_time); + start_time =ktime_get ();spin_unlock_irq (&chip->reg_lock);msleep (50 );spin_lock_irq (&chip->reg_lock);
@@ -2837,7 +2837,7 @@ static void intel8x0_measure_ac97_clock( pos += ichdev->position; } chip->in_measurement =0 ; -do_posix_clock_monotonic_gettime (&stop_time); + stop_time =ktime_get ();/* stop */ if (chip->device_type ==DEVICE_ALI ) {iputdword (chip,ICHREG (ALI_DMACR ),1 << (ichdev->ali_slot +16 ));
@@ -2865,9 +2865,7 @@ static void intel8x0_measure_ac97_clock( } pos /=4 ; - t = stop_time.tv_sec - start_time.tv_sec; - t *=1000000 ; - t += (stop_time.tv_nsec - start_time.tv_nsec) /1000 ; + t =ktime_us_delta (stop_time, start_time);dev_info (chip->card->dev,"%s: measured %lu usecs (%lu samples)\n" , __func__, t, pos);if (t ==0 ) {
Re: [patch 13/13] tomoyo: Use sensible time interface
In reply to Thomas GleixnerQuoted 3 lines · Thomas Gleixner
There is no point in calling gettimeofday if only the seconds part of the timespec is used. Use
get_seconds()instead. It's not only the proper interface it's also faster.
My only caution here is you only get tick-granular time here. So if the second rolled over after the last tick, you'd get the previous second when you call get_seconds(). This can cause some surprising effects if the get_seconds() return value is mixed with clocksource granular gettimeofday() calls.
thanks
-john
Re: [patch 13/13] tomoyo: Use sensible time interface
Quoted 10 lines · John Stultz
Quoted 3 lines · Thomas Gleixner
There is no point in calling gettimeofday if only the seconds part of the timespec is used. Use
get_seconds()instead. It's not only the proper interface it's also faster.My only caution here is you only get tick-granular time here. So if the second rolled over after the last tick, you'd get the previous second when you call
get_seconds(). This can cause some surprising effects if theget_seconds()return value is mixed with clocksource granulargettimeofday()calls.
If the whole thing only cares about the seconds value, then where is the problem?
Even if you call gettimeofday() then you still can observe this
gettimeofday(ts)
ts.tv_sec = 99 ts.tv_nsec = 999999999
So if you readout the related value ONE nanosecond later, then this value will have
ts.tv_sec = 100 ts.tv_nsec = 0
So what's the point? The tomoyo code chose to take seconds granular time stamps for whatever reasons. So it should be able to deal with that, right?
Thanks,
tglx
Re: [patch 13/13] tomoyo: Use sensible time interface
Quoted 22 lines · Thomas Gleixner
Quoted 10 lines · John Stultz
Quoted 3 lines · Thomas Gleixner
There is no point in calling gettimeofday if only the seconds part of the timespec is used. Use
get_seconds()instead. It's not only the proper interface it's also faster.My only caution here is you only get tick-granular time here. So if the second rolled over after the last tick, you'd get the previous second when you call
get_seconds(). This can cause some surprising effects if theget_seconds()return value is mixed with clocksource granulargettimeofday()calls.If the whole thing only cares about the seconds value, then where is the problem?
Even if you call
gettimeofday()then you still can observe thisgettimeofday(ts)
ts.tv_sec = 99 ts.tv_nsec = 999999999
Quoted 8 lines
So if you readout the related value ONE nanosecond later, then this value will have
ts.tv_sec = 100 ts.tv_nsec = 0So what's the point? The tomoyo code chose to take seconds granular time stamps for whatever reasons. So it should be able to deal with that, right?
No, the problem I'm warning about is if they were using gettimeofday() elsewhere in relation to those timestamps, they could see something like:
do_gettimeofday() { 99, 888....}get_seconds() { 99 }do_gettimeofday() { 99, 999....}get_seconds() { 99 }do_gettimeofday() { 100, 000....}get_seconds() { 99 }do_gettimeofday() { 100, 011....}get_seconds() { 100 }
This is the same problem people come across occasionally if they call gettimeofday, then create a file and fret that the file's timestamp seems to be before the gettimefoday call, and its all due to comparing timestamps with different granularities.
I'm not saying its a problem in this case, but I'm just throwing up some additional caution since the change you're making isn't completely equivalent.
thanks
-john
Re: [patch 13/13] tomoyo: Use sensible time interface
Quoted 45 lines · John Stultz
Quoted 22 lines · Thomas Gleixner
Quoted 10 lines · John Stultz
Quoted 3 lines · Thomas Gleixner
There is no point in calling gettimeofday if only the seconds part of the timespec is used. Use
get_seconds()instead. It's not only the proper interface it's also faster.My only caution here is you only get tick-granular time here. So if the second rolled over after the last tick, you'd get the previous second when you call
get_seconds(). This can cause some surprising effects if theget_seconds()return value is mixed with clocksource granulargettimeofday()calls.If the whole thing only cares about the seconds value, then where is the problem?
Even if you call
gettimeofday()then you still can observe thisgettimeofday(ts)
ts.tv_sec = 99 ts.tv_nsec = 999999999Quoted 8 lines
So if you readout the related value ONE nanosecond later, then this value will have
ts.tv_sec = 100 ts.tv_nsec = 0So what's the point? The tomoyo code chose to take seconds granular time stamps for whatever reasons. So it should be able to deal with that, right?
No, the problem I'm warning about is if they were using
gettimeofday()elsewhere in relation to those timestamps, they could see something like:
do_gettimeofday(){ 99, 888....}get_seconds(){ 99 }do_gettimeofday(){ 99, 999....}get_seconds(){ 99 }do_gettimeofday(){ 100, 000....}get_seconds(){ 99 }do_gettimeofday(){ 100, 011....}get_seconds(){ 100 }
Quoted 5 lines
This is the same problem people come across occasionally if they call gettimeofday, then create a file and fret that the file's timestamp seems to be before the gettimefoday call, and its all due to comparing timestamps with different granularities.
I'm aware of that, but there are only two places in that code which deal with time and both are calling do_gettimeofday and both just use the tv_sec part of it. And both of them are statistics.
One part of says clearly:
* I don't use atomic operations because race condition is not fatal.
Thanks,
tglx
RE: [patch 11/13] wireless: mwifiex: Use the proper interfaces
In reply to Thomas GleixnerHi Thomas,
Thanks for your patch.
Quoted 7 lines
Why is converting time formats so desired if there are proper interfaces for this?
Signed-off-by Thomas Gleixner <[email protected]>Cc Bing Zhao <[email protected]>Cc "John W. Linville" <[email protected]>
[...]
Quoted 27 lines
Index:
linux/drivers/net/wireless/mwifiex/main.c
===================================================================drivers/net/wireless/mwifiex/main.c +1
-3@@ -611,7 +611,6 @@ mwifiex_hard_start_xmit(struct sk_buff *struct mwifiex_private *priv =mwifiex_netdev_get_priv (dev);struct sk_buff *new_skb;struct mwifiex_txinfo *tx_info; -struct timeval tv;dev_dbg (priv->adapter->dev,"data: %lu BSS(%d-%d): Data <= kernel\n" , jiffies, priv->bss_type, priv->bss_num);@@ -658,8 +657,7 @@ mwifiex_hard_start_xmit(struct sk_buff ** firmware for aggregate delay calculation for stats and * MSDU lifetime expiry. */ -do_gettimeofday (&tv); - skb->tstamp =timeval_to_ktime (tv); +__net_timestamp (skb);mwifiex_queue_tx_pkt (priv, skb);Index:
linux/drivers/net/wireless/mwifiex/tdls.c
===================================================================
drivers/net/wireless/mwifiex/tdls.c int mwifiex_send_tdls_data_frame(struct · line 555
Quoted 6 lines
drivers/net/wireless/mwifiex/tdls.c +1
-2@@ -552,8 +552,7 @@ int mwifiex_send_tdls_data_frame(struct tx_info->bss_num = priv->bss_num; tx_info->bss_type = priv->bss_type; -do_gettimeofday (&tv); - skb->tstamp =timeval_to_ktime (tv); +__net_timestamp (skb);
I guess we need to remove "struct timeval tv" local variable too.
drivers/net/wireless/mwifiex/tdls.c int mwifiex_send_tdls_action_frame(struc · line 712
Quoted 10 lines
drivers/net/wireless/mwifiex/tdls.c +1
-2mwifiex_queue_tx_pkt (priv, skb);return 0 ;@@ -710,8 +709,7 @@ int mwifiex_send_tdls_action_frame(struc pkt_len = skb->len -MWIFIEX_MGMT_FRAME_HEADER_SIZE -sizeof (pkt_len);memcpy (skb->data +MWIFIEX_MGMT_FRAME_HEADER_SIZE , &pkt_len,sizeof (pkt_len)); -do_gettimeofday (&tv); - skb->tstamp =timeval_to_ktime (tv); +__net_timestamp (skb);
And here too.
Could you please remove these two "struct timeval tv" and send v2 with my ACK?
Thanks,
Bing
Quoted 3 lines
drivers/net/wireless/mwifiex/tdls.c +0
-0mwifiex_queue_tx_pkt (priv, skb);return 0 ;
Johannes Berg
maintainerRe: [patch 12/13] net: mac80211: Remove silly timespec dance
In reply to Thomas Gleixnernet/mac80211/status.c static void ieee80211_tx_latency_end_msr · line 508
Quoted 1 line · Thomas Gleixner
net/mac80211/status.c +1
-0+ msrmnt =ktime_to_ms (net_timedelta (skb_arv));
This is probably more of a question about net_timedelta(), but is ktime_get_real() really appropriate for duration measurements? Isn't that non-monotonic?
johannes
Johannes Berg
maintainerRe: [patch 04/13] net: mac80211: Use ktime_get_ts()
In reply to Thomas GleixnerQuoted 2 lines · Thomas Gleixner
do_posix_clock_monotonic_gettime()is a leftover from the initial posix timer implementation which maps toktime_get_ts().
I didn't even know we *had* such code, heh.
I've applied it to my tree - note that some code moved into sta_info.c recently there.
johannes
Re: [patch 12/13] net: mac80211: Remove silly timespec dance
In reply to Johannes BergQuoted 7 lines · Johannes Berg
net/mac80211/status.c static void ieee80211_tx_latency_end_msr · line 508
Quoted 1 line · Thomas Gleixner
net/mac80211/status.c +1
-0+ msrmnt =ktime_to_ms (net_timedelta (skb_arv));This is probably more of a question about
net_timedelta(), but isktime_get_real()really appropriate for duration measurements? Isn't that non-monotonic?
Well, it's monotonic, but might be affected by settimeofday().
Thanks,
tglx
PATCH v2 1/1 wireless: mwifiex: Use the proper interfaces
In reply to Bing ZhaoWhy is converting time formats so desired if there are proper interfaces for this?
--- drivers/net/wireless/mwifiex/cfg80211.c | 4 +--- drivers/net/wireless/mwifiex/main.c | 4 +--- drivers/net/wireless/mwifiex/tdls.c | 8 ++------ drivers/net/wireless/mwifiex/uap_txrx.c | 4 +--- drivers/net/wireless/mwifiex/wmm.c | 9 +-------- 5 files changed, 6 insertions(+), 23 deletions(-)
drivers/net/wireless/mwifiex/cfg80211.c +1 -3
@@ -151,7 +151,6 @@ mwifiex_form_mgmt_frame(struct sk_buff *u8 addr[ETH_ALEN ] = {0xFF ,0xFF ,0xFF ,0xFF ,0xFF ,0xFF };u16 pkt_len;u32 tx_control =0 , pkt_type =PKT_TYPE_MGMT ; -struct timeval tv; pkt_len = len +ETH_ALEN ;
@@ -173,8 +172,7 @@ mwifiex_form_mgmt_frame(struct sk_buff * len - sizeof(struct ieee80211_hdr_3addr)); skb->priority =LOW_PRIO_TID ; -do_gettimeofday (&tv); - skb->tstamp =timeval_to_ktime (tv); +__net_timestamp (skb);return 0 ; }
drivers/net/wireless/mwifiex/main.c +1 -3
@@ -611,7 +611,6 @@ mwifiex_hard_start_xmit(struct sk_buff *struct mwifiex_private *priv =mwifiex_netdev_get_priv (dev);struct sk_buff *new_skb;struct mwifiex_txinfo *tx_info; -struct timeval tv;dev_dbg (priv->adapter->dev,"data: %lu BSS(%d-%d): Data <= kernel\n" , jiffies, priv->bss_type, priv->bss_num);
@@ -658,8 +657,7 @@ mwifiex_hard_start_xmit(struct sk_buff ** firmware for aggregate delay calculation for stats and * MSDU lifetime expiry. */ -do_gettimeofday (&tv); - skb->tstamp =timeval_to_ktime (tv); +__net_timestamp (skb);mwifiex_queue_tx_pkt (priv, skb);
drivers/net/wireless/mwifiex/tdls.c +2 -6
@@ -474,7 +474,6 @@ int mwifiex_send_tdls_data_frame(struct {struct sk_buff *skb;struct mwifiex_txinfo *tx_info; -struct timeval tv;int ret;u16 skb_len;
@@ -552,8 +551,7 @@ int mwifiex_send_tdls_data_frame(struct tx_info->bss_num = priv->bss_num; tx_info->bss_type = priv->bss_type; -do_gettimeofday (&tv); - skb->tstamp =timeval_to_ktime (tv); +__net_timestamp (skb);mwifiex_queue_tx_pkt (priv, skb);return 0 ;
@@ -645,7 +643,6 @@ int mwifiex_send_tdls_action_frame(struc {struct sk_buff *skb;struct mwifiex_txinfo *tx_info; -struct timeval tv;u8 *pos;u32 pkt_type, tx_control;u16 pkt_len, skb_len;
@@ -710,8 +707,7 @@ int mwifiex_send_tdls_action_frame(struc pkt_len = skb->len -MWIFIEX_MGMT_FRAME_HEADER_SIZE -sizeof (pkt_len);memcpy (skb->data +MWIFIEX_MGMT_FRAME_HEADER_SIZE , &pkt_len,sizeof (pkt_len)); -do_gettimeofday (&tv); - skb->tstamp =timeval_to_ktime (tv); +__net_timestamp (skb);mwifiex_queue_tx_pkt (priv, skb);return 0 ;
drivers/net/wireless/mwifiex/uap_txrx.c +1 -3
@@ -96,7 +96,6 @@ static void mwifiex_uap_queue_bridged_pkstruct sk_buff *new_skb;struct mwifiex_txinfo *tx_info;int hdr_chop; -struct timeval tv;struct ethhdr *p_ethhdr; uap_rx_pd = (struct uap_rxpd *)(skb->data);
@@ -192,8 +191,7 @@ static void mwifiex_uap_queue_bridged_pk tx_info->pkt_len = skb->len; } -do_gettimeofday (&tv); - skb->tstamp =timeval_to_ktime (tv); +__net_timestamp (skb);mwifiex_wmm_add_buf_txqueue (priv, skb);atomic_inc (&adapter->tx_pending);atomic_inc (&adapter->pending_bridged_pkts);
drivers/net/wireless/mwifiex/wmm.c +1 -8
@@ -886,15 +886,8 @@ u8 mwifiex_wmm_compute_drv_pkt_delay(struct mwifiex_private *priv, const struct sk_buff *skb) { + u32 queue_delay = ktime_to_ms(net_timedelta(skb->tstamp));u8 ret_val; -struct timeval out_tstamp, in_tstamp; -u32 queue_delay; - -do_gettimeofday (&out_tstamp); - in_tstamp =ktime_to_timeval (skb->tstamp); - - queue_delay = (out_tstamp.tv_sec - in_tstamp.tv_sec) *1000 ; - queue_delay += (out_tstamp.tv_usec - in_tstamp.tv_usec) /1000 ;/* * Queue delay is passed as a uint8 in units of 2ms (ms shifted
Johannes Berg
maintainernet_timedelta() affected by settimeofday() (was: [patch 12/13] net: mac80211: Remove silly timespec dance)
In reply to Thomas Gleixner+netdev, Stephen
Quoted 11 lines · Thomas Gleixner
Quoted 7 lines · Johannes Berg
net/mac80211/status.c static void ieee80211_tx_latency_end_msr · line 508
Quoted 1 line · Thomas Gleixner
net/mac80211/status.c +1
-0+ msrmnt =ktime_to_ms (net_timedelta (skb_arv));This is probably more of a question about
net_timedelta(), but isktime_get_real()really appropriate for duration measurements? Isn't that non-monotonic?Well, it's monotonic, but might be affected by
settimeofday().
Right, but isn't that odd? Suddenly your delay measurement here might be minutes, hours, or years if you settimeofday() between timestamping and calculating the delta. That seems very strange to me, why would that be the right behaviour in any way?
Now, it seems that there are only two current users of net_timedelta() (in DCCP) so perhaps it's not too late to change some of this?
Maybe in general the skb timestamp should be based on a different clock and only adjusted to real time when used in userspace?
johannes
Johannes Berg
maintainerRe: [patch V2] wireless: mwifiex: Use the proper interfaces
In reply to Thomas Gleixnerdrivers/net/wireless/mwifiex/wmm.c u8 · line 889
Quoted 1 line · Thomas Gleixner
drivers/net/wireless/mwifiex/wmm.c +1
-0+u32 queue_delay =ktime_to_ms (net_timedelta (skb->tstamp));
FWIW, I think the same as patch 12 applies here. net_timedelta() doesn't really seem to be a good way to calculate time deltas.
And yes - I've seen situations where this matters, e.g. when running ntpdate after system startup.
johannes
Johannes Berg
maintainerRe: net_timedelta() affected by settimeofday() (was: [patch 12/13] net: mac80211: Remove silly timespec dance)
In reply to Johannes BergQuoted 1 line · Johannes Berg
+netdev, Stephen
Well, stupid me. Fixing that netdev address.
Quoted 23 lines · Thomas Gleixner
Quoted 11 lines · Johannes Berg
Quoted 8 lines · Thomas Gleixner
net/mac80211/status.c static void ieee80211_tx_latency_end_msr · line 508
Quoted 2 lines
net/mac80211/status.c +1
-0+ msrmnt =ktime_to_ms (net_timedelta (skb_arv));This is probably more of a question about
net_timedelta(), but isktime_get_real()really appropriate for duration measurements? Isn't that non-monotonic?Well, it's monotonic, but might be affected by
settimeofday().Right, but isn't that odd? Suddenly your delay measurement here might be minutes, hours, or years if you
settimeofday()between timestamping and calculating the delta. That seems very strange to me, why would that be the right behaviour in any way?Now, it seems that there are only two current users of
net_timedelta()(in DCCP) so perhaps it's not too late to change some of this?Maybe in general the skb timestamp should be based on a different clock and only adjusted to real time when used in userspace?
Re: net_timedelta() affected by settimeofday() (was: [patch 12/13] net: mac80211: Remove silly timespec dance)
Quoted 22 lines · Johannes Berg
Quoted 1 line · Johannes Berg
+netdev, Stephen
Well, stupid me. Fixing that netdev address.
Quoted 17 lines · Thomas Gleixner
Quoted 11 lines · Johannes Berg
Quoted 8 lines · Thomas Gleixner
net/mac80211/status.c static void ieee80211_tx_latency_end_msr · line 508
Quoted 2 lines
net/mac80211/status.c +1
-0+ msrmnt =ktime_to_ms (net_timedelta (skb_arv));This is probably more of a question about
net_timedelta(), but isktime_get_real()really appropriate for duration measurements? Isn't that non-monotonic?Well, it's monotonic, but might be affected by
settimeofday().Right, but isn't that odd? Suddenly your delay measurement here might be minutes, hours, or years if you
settimeofday()between timestamping and calculating the delta. That seems very strange to me, why would that be the right behaviour in any way?
Indeed. clock monotonic is the appropriate one for measurements.
Quoted 5 lines
Quoted 5 lines
Now, it seems that there are only two current users of
net_timedelta()(in DCCP) so perhaps it's not too late to change some of this?Maybe in general the skb timestamp should be based on a different clock and only adjusted to real time when used in userspace?
You have the same problem then, just at a different place:
ts = ktime_get();
settimeofday()
offset_mono_to_real = new value;
userts = mono_to_real(ts);But maybe that's not a real issue, as ktime_get_real() can race with settimeofday() or NTP as well.
ts = ktime_get_real(); settimeofday();
userts = ts;
So the user might see a weird timestamp for a packet, which cannot be correlated with the user space gettimeofday().
Thanks,
tglx
Re: [patch 04/13] net: mac80211: Use ktime_get_ts()
In reply to Johannes BergQuoted 6 lines · Johannes Berg
Quoted 2 lines · Thomas Gleixner
do_posix_clock_monotonic_gettime()is a leftover from the initial posix timer implementation which maps toktime_get_ts().I didn't even know we *had* such code, heh.
If we want want maintainers to police this stuff we can add an SmPL rule for this upstream and have maintainer use 'make coccicheck M=path/'. The way of the future. The way of the future...
Luis
Johannes Berg
maintainerRe: net_timedelta() affected by settimeofday() (was: [patch 12/13] net: mac80211: Remove silly timespec dance)
In reply to Thomas GleixnerQuoted 6 lines · Thomas Gleixner
Quoted 4 lines
Quoted 4 lines
Right, but isn't that odd? Suddenly your delay measurement here might be minutes, hours, or years if you
settimeofday()between timestamping and calculating the delta. That seems very strange to me, why would that be the right behaviour in any way?Indeed. clock monotonic is the appropriate one for measurements.
And that's what we had here with ktime_get_ts()? I thought so, just making sure.
Quoted 6 lines
Quoted 5 lines
Quoted 5 lines
Now, it seems that there are only two current users of
net_timedelta()(in DCCP) so perhaps it's not too late to change some of this?Maybe in general the skb timestamp should be based on a different clock and only adjusted to real time when used in userspace?
Quoted 8 lines
You have the same problem then, just at a different place:
ts = ktime_get(); settimeofday() offset_mono_to_real = new value; userts = mono_to_real(ts);
Right. I'm not really sure if that's an issue though.
Quoted 9 lines
But maybe that's not a real issue, as
ktime_get_real()can race withsettimeofday()or NTP as well.ts = ktime_get_real(); settimeofday(); userts = ts;So the user might see a weird timestamp for a packet, which cannot be correlated with the user space
gettimeofday().
Right, once settimeofday() is called the timestamps from before/during it can't really be correlated any more.
This is part of the userspace API already, but might it have been better to expose the monotonic clock, since userspace can also get at it? Not sure.
Either way it's an issue I guess; however I'm thinking your patch is making it worse for the measurement in this particular code (where the userspace issue doesn't come in, it should never be accessible there)
johannes
Re: [Cocci] [patch 04/13] net: mac80211: Use ktime_get_ts()
In reply to Luis R. Rodriguez"Luis R. Rodriguez" <[email protected]> a ?crit?:
Quoted 4 lines
Quoted 2 lines · Johannes Berg
On Wed, 2014-06-11 at 23:59 +0000, Thomas Gleixner wrote:
Quoted 8 lines
Quoted 4 lines
Quoted 2 lines
do_posix_clock_monotonic_gettime()is a leftover from the initial posix timer implementation which maps toktime_get_ts().I didn't even know we *had* such code, heh.
If we want want maintainers to police this stuff we can add an SmPL rule for this upstream and have maintainer use 'make coccicheck M=path/'. The way of the future. The way of the future...
If I could have a little more context, I can do something.
julia
Quoted 7 lines
Luis
_______________________________________________
Cocci mailing list
Cocci at systeme.lip6.fr
https://systeme.lip6.fr/mailman/listinfo/cocci
Re: [patch 05/13] sound: Use ktime_get_ts()
In reply to Thomas GleixnerAt Wed, 11 Jun 2014 23:59:14 -0000,
Quoted 7 lines · Thomas Gleixner
do_posix_clock_monotonic_gettime()is a leftover from the initial posix timer implementation which maps toktime_get_ts().Signed-off-by Thomas Gleixner <[email protected]>Cc Jaroslav Kysela <[email protected]>Cc Takashi Iwai <[email protected]>
Shall I apply these patches 5 and 6 to sound git tree, or would you like to apply all in tip tree instead? In the latter case, feel free to take my ack for both patches:
thanks,
Takashi
Quoted 42 lines
--- include/sound/pcm.h | 2 +- sound/core/timer.c | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-)Index:
linux/include/sound/pcm.h
===================================================================include/sound/pcm.h +1
-1@@ -932,7 +932,7 @@ static inline void snd_pcm_gettime(struc struct timespec *tv) {if (runtime->tstamp_type ==SNDRV_PCM_TSTAMP_TYPE_MONOTONIC ) -do_posix_clock_monotonic_gettime (tv); +ktime_get_ts (tv);else getnstimeofday (tv); }Index:
linux/sound/core/timer.c
===================================================================sound/core/timer.c +2
-2@@ -390,7 +390,7 @@ static void snd_timer_notify1(struct sndstruct timespec tstamp;if (timer_tstamp_monotonic) -do_posix_clock_monotonic_gettime (&tstamp); +ktime_get_ts (&tstamp);else getnstimeofday (&tstamp); if (snd_BUG_ON(event < SNDRV_TIMER_EVENT_START ||@@ -1203,7 +1203,7 @@ static void snd_timer_user_tinterrupt(st }if (tu->last_resolution != resolution || ticks >0 ) {if (timer_tstamp_monotonic) -do_posix_clock_monotonic_gettime (&tstamp); +ktime_get_ts (&tstamp);else getnstimeofday (&tstamp); }
Re: [Cocci] [patch 04/13] net: mac80211: Use ktime_get_ts()
In reply to [email protected]Quoted 9 lines · On Thu, 12 Jun 2014, Julia.Lawall at lip6.fr wrote:
"Luis R. Rodriguez" <[email protected]> a ?crit?:
Quoted 7 lines
Quoted 5 lines · Johannes Berg
Quoted 2 lines · Thomas Gleixner
do_posix_clock_monotonic_gettime()is a leftover from the initial posix timer implementation which maps toktime_get_ts().
Quoted 7 lines
Quoted 5 lines
Quoted 1 line
I didn't even know we *had* such code, heh.
If we want want maintainers to police this stuff we can add an SmPL rule for this upstream and have maintainer use 'make coccicheck M=path/'. The way of the future. The way of the future...
If I could have a little more context, I can do something.
I already killed all instances of do_posix_clock_monotonic_gettime(). The define will be gone soon, so nothing to worry about.
Thanks,
tglx
Re: [patch 05/13] sound: Use ktime_get_ts()
In reply to Takashi IwaiQuoted 10 lines · Takashi Iwai
At Wed, 11 Jun 2014 23:59:14 -0000,
Quoted 7 lines · Thomas Gleixner
do_posix_clock_monotonic_gettime()is a leftover from the initial posix timer implementation which maps toktime_get_ts().Signed-off-by Thomas Gleixner <[email protected]>Cc Jaroslav Kysela <[email protected]>Cc Takashi Iwai <[email protected]>
Quoted 5 lines
Shall I apply these patches 5 and 6 to sound git tree, or would you like to apply all in tip tree instead? In the latter case, feel free to take my ack for both patches:
Reviewed-by Takashi Iwai <[email protected]>
Please take them via sound.
Thanks,
tglx
Re: [patch 05/13] sound: Use ktime_get_ts()
At Thu, 12 Jun 2014 12:51:07 +0200 (CEST),
Quoted 13 lines · Thomas Gleixner
Quoted 10 lines · Takashi Iwai
At Wed, 11 Jun 2014 23:59:14 -0000,
Quoted 7 lines · Thomas Gleixner
do_posix_clock_monotonic_gettime()is a leftover from the initial posix timer implementation which maps toktime_get_ts().Signed-off-by Thomas Gleixner <[email protected]>Cc Jaroslav Kysela <[email protected]>Cc Takashi Iwai <[email protected]>
Quoted 7 lines
Quoted 5 lines
Shall I apply these patches 5 and 6 to sound git tree, or would you like to apply all in tip tree instead? In the latter case, feel free to take my ack for both patches:
Reviewed-by Takashi Iwai <[email protected]>Please take them via sound.
OK, applied both now. Thanks.
Takashi
Re: [patch 13/13] tomoyo: Use sensible time interface
In reply to Thomas GleixnerQuoted 7 lines · Thomas Gleixner
There is no point in calling gettimeofday if only the seconds part of the timespec is used. Use
get_seconds()instead. It's not only the proper interface it's also faster.Signed-off-by Thomas Gleixner <[email protected]>Cc Kentaro Takeda <[email protected]>
Quoted 8 lines · John Stultz
do_gettimeofday(){ 99, 888....}get_seconds(){ 99 }do_gettimeofday(){ 99, 999....}get_seconds(){ 99 }do_gettimeofday(){ 100, 000....}get_seconds(){ 99 }do_gettimeofday(){ 100, 011....}get_seconds(){ 100 }
That will be acceptable error for TOMOYO. Thank you.
Re: [patch 08/13] firewire: Use ktime_get_ts()
In reply to Thomas GleixnerQuoted 5 lines · On Jun 11 Thomas Gleixner wrote:
do_posix_clock_monotonic_gettime()is a leftover from the initial posix timer implementation which maps toktime_get_ts()Signed-off-by Thomas Gleixner <[email protected]>Cc Stefan Richter <[email protected]>
(Though I am noticing increasing entropy WRT whitespace.)
Quoted 19 lines
--- drivers/firewire/core-cdev.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)Index:
linux/drivers/firewire/core-cdev.c
===================================================================drivers/firewire/core-cdev.c +1
-1@@ -1215,7 +1215,7 @@ static int ioctl_get_cycle_timer2(structswitch (a->clk_id) {case CLOCK_REALTIME :getnstimeofday (&ts);break ; -case CLOCK_MONOTONIC :do_posix_clock_monotonic_gettime (&ts);break ; +case CLOCK_MONOTONIC :ktime_get_ts (&ts);break ;case CLOCK_MONOTONIC_RAW :getrawmonotonic (&ts);break ;default : ret = -EINVAL ;
Signature · 3 lines
Stefan Richter -=====-====- -==- -==-- http://arcgraph.de/sr/
Re: net_timedelta() affected by settimeofday() (was: [patch 12/13] net: mac80211: Remove silly timespec dance)
In reply to Johannes BergQuoted 42 lines · Johannes Berg
Quoted 6 lines · Thomas Gleixner
Quoted 4 lines
Quoted 4 lines
Right, but isn't that odd? Suddenly your delay measurement here might be minutes, hours, or years if you
settimeofday()between timestamping and calculating the delta. That seems very strange to me, why would that be the right behaviour in any way?Indeed. clock monotonic is the appropriate one for measurements.
And that's what we had here with
ktime_get_ts()? I thought so, just making sure.Quoted 6 lines
Quoted 5 lines
Quoted 5 lines
Now, it seems that there are only two current users of
net_timedelta()(in DCCP) so perhaps it's not too late to change some of this?Maybe in general the skb timestamp should be based on a different clock and only adjusted to real time when used in userspace?
Quoted 8 lines
You have the same problem then, just at a different place:
ts = ktime_get(); settimeofday() offset_mono_to_real = new value; userts = mono_to_real(ts);Right. I'm not really sure if that's an issue though.
Quoted 9 lines
But maybe that's not a real issue, as
ktime_get_real()can race withsettimeofday()or NTP as well.ts = ktime_get_real(); settimeofday(); userts = ts;So the user might see a weird timestamp for a packet, which cannot be correlated with the user space
gettimeofday().Right, once
settimeofday()is called the timestamps from before/during it can't really be correlated any more.
Quoted 7 lines
This is part of the userspace API already, but might it have been better to expose the monotonic clock, since userspace can also get at it? Not sure.
Either way it's an issue I guess; however I'm thinking your patch is making it worse for the measurement in this particular code (where the userspace issue doesn't come in, it should never be accessible there)
Fair enough. Still the timespec is silly. Here is an updated version.
Thanks,
tglx
------------------>
Subject: net: Mac80211: Remove silly timespec dance
From: Thomas Gleixner <[email protected]>
Date: Wed, 11 Jun 2014 23:59:18 -0000
Converting time from one format to another seems to give coders a warm and fuzzy feeling.
Use the proper interfaces.
--- net/mac80211/status.c | 7 ++----- net/mac80211/tx.c | 5 +---- 2 files changed, 3 insertions(+), 9 deletions(-)
net/mac80211/status.c +2 -5
@@ -473,8 +473,6 @@ static void ieee80211_tx_latency_end_msrstruct sta_info *sta, struct ieee80211_hdr *hdr) { - ktime_t skb_dprt; -struct timespec dprt_time; u32 msrmnt;u16 tid;u8 *qc;
@@ -506,9 +504,8 @@ static void ieee80211_tx_latency_end_msr tx_lat = &sta->tx_lat[tid]; -ktime_get_ts (&dprt_time);/* time stamp completion time */ - skb_dprt =ktime_set (dprt_time.tv_sec, dprt_time.tv_nsec); - msrmnt =ktime_to_ms (ktime_sub (skb_dprt, skb_arv)); +/* Calculate the latency */ + msrmnt = ktime_to_ms(ktime_sub(ktime_get(), skb_arv);if (tx_lat->max < msrmnt)/* update stats */ tx_lat->max = msrmnt;
net/mac80211/tx.c +0 -1
@@ -1767,15 +1767,12 @@ fail:static void ieee80211_tx_latency_start_msrmnt (struct ieee80211_local *local,struct sk_buff *skb) { -struct timespec skb_arv;struct ieee80211_tx_latency_bin_ranges *tx_latency; tx_latency =rcu_dereference (local->tx_latency);if (!tx_latency)return ;
Re: [patch 08/13] firewire: Use ktime_get_ts()
In reply to Stefan RichterQuoted 10 lines · Stefan Richter
Quoted 5 lines · On Jun 11 Thomas Gleixner wrote:
do_posix_clock_monotonic_gettime()is a leftover from the initial posix timer implementation which maps toktime_get_ts()Signed-off-by Thomas Gleixner <[email protected]>Cc Stefan Richter <[email protected]>Acked-by Stefan Richter <[email protected]>(Though I am noticing increasing entropy WRT whitespace.)
Fixed it up.
Johannes Berg
maintainerRe: net_timedelta() affected by settimeofday() (was: [patch 12/13] net: mac80211: Remove silly timespec dance)
In reply to Thomas GleixnerQuoted 1 line · Thomas Gleixner
Fair enough. Still the timespec is silly. Here is an updated version.
Makes sense, thanks. I've applied this (mac80211-next)
johannes
RE: [patch V2] wireless: mwifiex: Use the proper interfaces
In reply to Johannes BergDQo+ID4gKwl1MzIgcXVldWVfZGVsYXkgPSBrdGltZV90b19tcyhuZXRfdGltZWRlbHRhKHNrYi0+ dHN0YW1wKSk7DQo+IA0KPiBGV0lXLCBJIHRoaW5rIHRoZSBzYW1lIGFzIHBhdGNoIDEyIGFwcGxp ZXMgaGVyZS4gbmV0X3RpbWVkZWx0YSgpIGRvZXNuJ3QNCj4gcmVhbGx5IHNlZW0gdG8gYmUgYSBn b29kIHdheSB0byBjYWxjdWxhdGUgdGltZSBkZWx0YXMuDQoNClNoYWxsIHdlIGNoYW5nZSBuZXRf dGltZWRlbHRhIHRvIGt0aW1lX3N1YigpIHVzaW5nIGt0aW1lX2dldCgpPw0KDQorCXUzMiBxdWV1 ZV9kZWxheSA9IGt0aW1lX3RvX21zKGt0aW1lX3N1YihrdGltZV9nZXQoKSwgc2tiLT50c3RhbXAp KTsNCg0KVGhhbmtzLA0KQmluZw0KDQo+IA0KPiBBbmQgeWVzIC0gSSd2ZSBzZWVuIHNpdHVhdGlv bnMgd2hlcmUgdGhpcyBtYXR0ZXJzLCBlLmcuIHdoZW4gcnVubmluZw0KPiBudHBkYXRlIGFmdGVy IHN5c3RlbSBzdGFydHVwLg0KPiANCj4gam9oYW5uZXMNCj4gDQoNCg==
tip-bot for Thomas Gleixner
merge bot[tip:timers/core] acct: Use ktime_get_ts()
In reply to Thomas Gleixneracct: Use ktime_get_ts()
Commit-ID: 22001821d9cb6ddb83ee4e1f81e6b905de623165 Gitweb: http://git.kernel.org/tip/22001821d9cb6ddb83ee4e1f81e6b905de623165 Author: Thomas Gleixner <[email protected]> AuthorDate: Wed, 11 Jun 2014 23:59:12 +0000 Committer: Thomas Gleixner <[email protected]> CommitDate: Thu, 12 Jun 2014 16:18:44 +0200
acct: Use ktime_get_ts()
do_posix_clock_monotonic_gettime() is a leftover from the initial posix timer implementation which maps to ktime_get_ts()
--- kernel/acct.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/acct.c +1 -1
@@ -484,7 +484,7 @@ static void do_acct_process(struct bsd_acct_struct *acct,strlcpy (ac.ac_comm, current->comm,sizeof (ac.ac_comm));/* calculate run_time in nsec*/ -do_posix_clock_monotonic_gettime (&uptime); +ktime_get_ts (&uptime); run_time = (u64 )uptime.tv_sec*NSEC_PER_SEC + uptime.tv_nsec; run_time -= (u64 )current->group_leader->start_time.tv_sec *NSEC_PER_SEC + current->group_leader->start_time.tv_nsec;
tip-bot for Thomas Gleixner
merge bot[tip:timers/core] delayacct: Use ktime_get_ts()
In reply to Thomas Gleixnerdelayacct: Use ktime_get_ts()
Commit-ID: b5d7682533941edb121f7495bdb2a17abac03ff3 Gitweb: http://git.kernel.org/tip/b5d7682533941edb121f7495bdb2a17abac03ff3 Author: Thomas Gleixner <[email protected]> AuthorDate: Wed, 11 Jun 2014 23:59:13 +0000 Committer: Thomas Gleixner <[email protected]> CommitDate: Thu, 12 Jun 2014 16:18:45 +0200
delayacct: Use ktime_get_ts()
do_posix_clock_monotonic_gettime() is a leftover from the initial posix timer implementation which maps to ktime_get_ts(). Remove the silly wrapper while at it.
--- kernel/delayacct.c | 16 +++------------- 1 file changed, 3 insertions(+), 13 deletions(-)
kernel/delayacct.c +3 -13
@@ -46,16 +46,6 @@ void __delayacct_tsk_init(struct task_struct *tsk) }/* -* Start accounting for a delay statistic using -* its starting timestamp (@start) -*/ - -static inline void delayacct_start (struct timespec *start) -{ -do_posix_clock_monotonic_gettime (start); -} - -/* * Finish delay accounting for a statistic using * its timestamps (@start, @end), accumalator (@total) and @count */
@@ -67,7 +57,7 @@ static void delayacct_end(struct timespec *start, struct timespec *end,s64 ns;unsigned long flags; -do_posix_clock_monotonic_gettime (end); +ktime_get_ts (end); ts =timespec_sub (*end, *start); ns =timespec_to_ns (&ts);if (ns <0 )
@@ -81,7 +71,7 @@ static void delayacct_end(struct timespec *start, struct timespec *end,void __delayacct_blkio_start (void ) { -delayacct_start (¤t->delays->blkio_start); +ktime_get_ts (¤t->delays->blkio_start); }void __delayacct_blkio_end (void )
@@ -169,7 +159,7 @@ __u64 __delayacct_blkio_ticks(struct task_struct *tsk)void __delayacct_freepages_start (void ) { -delayacct_start (¤t->delays->freepages_start); +ktime_get_ts (¤t->delays->freepages_start); }void __delayacct_freepages_end (void )
tip-bot for Thomas Gleixner
merge bot[tip:timers/core] tsacct: Use ktime_get_ts()
In reply to Thomas Gleixnertsacct: Use ktime_get_ts()
Commit-ID: 4e8c5847d1c55efed896508fb769f78ab07b968a Gitweb: http://git.kernel.org/tip/4e8c5847d1c55efed896508fb769f78ab07b968a Author: Thomas Gleixner <[email protected]> AuthorDate: Wed, 11 Jun 2014 23:59:13 +0000 Committer: Thomas Gleixner <[email protected]> CommitDate: Thu, 12 Jun 2014 16:18:45 +0200
tsacct: Use ktime_get_ts()
do_posix_clock_monotonic_gettime() is a leftover from the initial posix timer implementation which maps to ktime_get_ts()
--- kernel/tsacct.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/tsacct.c +1 -1
@@ -38,7 +38,7 @@ void bacct_add_tsk(struct user_namespace *user_ns,BUILD_BUG_ON (TS_COMM_LEN <TASK_COMM_LEN );/* calculate task elapsed time in timespec */ -do_posix_clock_monotonic_gettime (&uptime); +ktime_get_ts (&uptime); ts =timespec_sub (uptime, tsk->start_time);/* rebase elapsed time to usec (should never be negative) */ ac_etime =timespec_to_ns (&ts);
tip-bot for Thomas Gleixner
merge bot[tip:timers/core] kdb: Use ktime_get_ts()
In reply to Thomas Gleixnerkdb: Use ktime_get_ts()
Commit-ID: a9821c741c960a77a7f08491883f9cc4bffd2279 Gitweb: http://git.kernel.org/tip/a9821c741c960a77a7f08491883f9cc4bffd2279 Author: Thomas Gleixner <[email protected]> AuthorDate: Wed, 11 Jun 2014 23:59:16 +0000 Committer: Thomas Gleixner <[email protected]> CommitDate: Thu, 12 Jun 2014 16:18:45 +0200
kdb: Use ktime_get_ts()
do_posix_clock_monotonic_gettime() is a leftover from the initial posix timer implementation which maps to ktime_get_ts().
--- kernel/debug/kdb/kdb_main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/debug/kdb/kdb_main.c +1 -1
@@ -2472,7 +2472,7 @@ static void kdb_gmtime(struct timespec *tv, struct kdb_tm *tm)static void kdb_sysinfo (struct sysinfo *val) {struct timespec uptime; -do_posix_clock_monotonic_gettime (&uptime); +ktime_get_ts (&uptime);memset (val,0 ,sizeof (*val)); val->uptime = uptime.tv_sec; val->loads[0 ] = avenrun[0 ];
tip-bot for Thomas Gleixner
merge bot[tip:timers/core] firewire: Use ktime_get_ts()
In reply to Thomas Gleixnerfirewire: Use ktime_get_ts()
Commit-ID: 889235ce2b26cdd231c7a1d6005928ec42f11637 Gitweb: http://git.kernel.org/tip/889235ce2b26cdd231c7a1d6005928ec42f11637 Author: Thomas Gleixner <[email protected]> AuthorDate: Wed, 11 Jun 2014 23:59:16 +0000 Committer: Thomas Gleixner <[email protected]> CommitDate: Thu, 12 Jun 2014 16:18:45 +0200
firewire: Use ktime_get_ts()
do_posix_clock_monotonic_gettime() is a leftover from the initial posix timer implementation which maps to ktime_get_ts()
--- drivers/firewire/core-cdev.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/firewire/core-cdev.c +3 -3
@@ -1214,9 +1214,9 @@ static int ioctl_get_cycle_timer2(struct client *client, union ioctl_arg *arg) cycle_time = card->driver->read_csr (card,CSR_CYCLE_TIME );switch (a->clk_id) { -case CLOCK_REALTIME :getnstimeofday (&ts);break ; -case CLOCK_MONOTONIC :do_posix_clock_monotonic_gettime (&ts);break ; -case CLOCK_MONOTONIC_RAW :getrawmonotonic (&ts);break ; +case CLOCK_REALTIME :getnstimeofday (&ts);break ; +case CLOCK_MONOTONIC :ktime_get_ts (&ts);break ; +case CLOCK_MONOTONIC_RAW :getrawmonotonic (&ts);break ;default : ret = -EINVAL ; }
tip-bot for Thomas Gleixner
merge bot[tip:timers/core] fork: Use ktime_get_ts()
In reply to Thomas Gleixnerfork: Use ktime_get_ts()
Commit-ID: f037c1171db79be2a047b1a5aafa2fd1f05051cb Gitweb: http://git.kernel.org/tip/f037c1171db79be2a047b1a5aafa2fd1f05051cb Author: Thomas Gleixner <[email protected]> AuthorDate: Wed, 11 Jun 2014 23:59:17 +0000 Committer: Thomas Gleixner <[email protected]> CommitDate: Thu, 12 Jun 2014 16:18:45 +0200
fork: Use ktime_get_ts()
do_posix_clock_monotonic_gettime() is a leftover from the initial posix timer implementation which maps to ktime_get_ts().
--- kernel/fork.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/fork.c +1 -1
@@ -1262,7 +1262,7 @@ static struct task_struct *copy_process(unsigned long clone_flags,posix_cpu_timers_init (p); -do_posix_clock_monotonic_gettime (&p->start_time); +ktime_get_ts (&p->start_time); p->real_start_time = p->start_time;monotonic_to_bootbased (&p->real_start_time); p->io_context =NULL ;
tip-bot for Thomas Gleixner
merge bot[tip:timers/core] tomoyo: Use sensible time interface
In reply to Thomas Gleixnertomoyo: Use sensible time interface
Commit-ID: 77f4fa089c724adc3a87c10eb031bca91b144ac0 Gitweb: http://git.kernel.org/tip/77f4fa089c724adc3a87c10eb031bca91b144ac0 Author: Thomas Gleixner <[email protected]> AuthorDate: Wed, 11 Jun 2014 23:59:19 +0000 Committer: Thomas Gleixner <[email protected]> CommitDate: Thu, 12 Jun 2014 16:18:45 +0200
tomoyo: Use sensible time interface
There is no point in calling gettimeofday if only the seconds part of the timespec is used. Use get_seconds() instead. It's not only the proper interface it's also faster.
--- security/tomoyo/audit.c | 8 +++----- security/tomoyo/common.c | 4 +--- 2 files changed, 4 insertions(+), 8 deletions(-)
security/tomoyo/audit.c +3 -5
@@ -155,11 +155,9 @@ static char *tomoyo_print_header(struct tomoyo_request_info *r)u8 i;if (!buffer)return NULL ; - { -struct timeval tv; -do_gettimeofday (&tv); -tomoyo_convert_time (tv.tv_sec, &stamp); - } + +tomoyo_convert_time (get_seconds (), &stamp); + pos =snprintf (buffer, tomoyo_buffer_len -1 ,"#%04u/%02u/%02u %02u:%02u:%02u# profile=%u mode=%s " "granted=%s (global-pid=%u) task={ pid=%u ppid=%u "
security/tomoyo/common.c +1 -3
@@ -2267,13 +2267,11 @@ static unsigned int tomoyo_stat_modified[TOMOYO_MAX_POLICY_STAT];*/ void tomoyo_update_stat (const u8 index) { -struct timeval tv; -do_gettimeofday (&tv);/* * I don't use atomic operations because race condition is not fatal. */ tomoyo_stat_updated[index]++; - tomoyo_stat_modified[index] = tv.tv_sec; + tomoyo_stat_modified[index] =get_seconds (); }/**