struct list_head js_list; /* on ojs_list, with ojs_lock */
atomic_t js_refcount; /* num users of this struct */
char js_jobid[LUSTRE_JOBID_SIZE]; /* job name + NUL*/
- time64_t js_timestamp; /* seconds of most recent stat*/
+ ktime_t js_time_init; /* time of initial stat*/
+ ktime_t js_time_latest; /* time of most recent stat*/
struct lprocfs_stats *js_stats; /* per-job statistics */
struct obd_job_stats *js_jobstats; /* for accessing ojs_lock */
};
struct cfs_hash_bd *bd,
struct hlist_node *hnode, void *data)
{
- time64_t oldest_time = *((time64_t *)data);
+ ktime_t oldest_time = *((ktime_t *)data);
struct job_stat *job;
job = hlist_entry(hnode, struct job_stat, js_hash);
- if (job->js_timestamp < oldest_time)
+ if (ktime_before(job->js_time_latest, oldest_time))
cfs_hash_bd_del_locked(hs, bd, hnode);
return 0;
*
* Since this function may be called frequently, do not scan all of the
* jobstats on each call, only twice per cleanup interval. That means stats
- * may be around on average cleanup_interval / 4 longer than necessary,
- * but that is not considered harmful.
+ * may be on average around cleanup_interval / 4 older than the cleanup
+ * interval, but that is not considered harmful.
*
- * If \a before is negative then this will force clean up all jobstats due
- * to the expiry time being in the future (e.g. at shutdown).
+ * The value stored in ojs_cleanup_interval is how often to perform a cleanup
+ * scan, and 1/2 of the maximum age of the individual statistics. This is
+ * done rather than dividing the interval by two each time, because it is
+ * much easier to do the division when the value is initially set (in seconds)
+ * rather than after it has been converted to ktime_t, and maybe a bit faster.
+ *
+ * If \a clear is true then this will force clean up all jobstats
+ * (e.g. at shutdown).
*
* If there is already another thread doing jobstats cleanup, don't try to
* do this again in the current thread unless this is a force cleanup.
*
* \param[in] stats stucture tracking all job stats for this device
- * \param[in] before expire jobstats updated more than this many seconds ago
+ * \param[in] clear clear all job stats if true
*/
-static void lprocfs_job_cleanup(struct obd_job_stats *stats, int before)
+static void lprocfs_job_cleanup(struct obd_job_stats *stats, bool clear)
{
- time64_t now = ktime_get_real_seconds();
- time64_t oldest;
-
- if (likely(before >= 0)) {
- unsigned int cleanup_interval = stats->ojs_cleanup_interval;
+ ktime_t cleanup_interval = stats->ojs_cleanup_interval;
+ ktime_t now = ktime_get();
+ ktime_t oldest;
- if (cleanup_interval == 0 || before == 0)
+ if (likely(!clear)) {
+ /* ojs_cleanup_interval of zero means never clean up stats */
+ if (ktime_to_ns(cleanup_interval) == 0)
return;
- if (now < stats->ojs_last_cleanup + cleanup_interval / 2)
+ if (ktime_before(now, ktime_add(stats->ojs_cleanup_last,
+ cleanup_interval)))
return;
if (stats->ojs_cleaning)
}
write_lock(&stats->ojs_lock);
- if (before >= 0 && stats->ojs_cleaning) {
+ if (!clear && stats->ojs_cleaning) {
write_unlock(&stats->ojs_lock);
return;
}
* Holding ojs_lock isn't necessary for safety of the hash iteration,
* since locking of the hash is handled internally, but there isn't
* any benefit to having multiple threads doing cleanup at one time.
+ *
+ * Subtract twice the cleanup_interval, since it is 1/2 the maximum age.
*/
- oldest = now - before;
+ oldest = ktime_sub(now, ktime_add(cleanup_interval, cleanup_interval));
cfs_hash_for_each_safe(stats->ojs_hash, job_cleanup_iter_callback,
&oldest);
write_lock(&stats->ojs_lock);
stats->ojs_cleaning = false;
- stats->ojs_last_cleanup = ktime_get_real_seconds();
+ stats->ojs_cleanup_last = ktime_get();
write_unlock(&stats->ojs_lock);
}
jobs->ojs_cntr_init_fn(job->js_stats, 0);
memcpy(job->js_jobid, jobid, sizeof(job->js_jobid));
- job->js_timestamp = ktime_get_real_seconds();
+ job->js_time_init = ktime_get();
+ job->js_time_latest = job->js_time_init;
job->js_jobstats = jobs;
INIT_HLIST_NODE(&job->js_hash);
INIT_LIST_HEAD(&job->js_list);
if (job)
goto found;
- lprocfs_job_cleanup(stats, stats->ojs_cleanup_interval);
+ lprocfs_job_cleanup(stats, false);
job = job_alloc(jobid, stats);
if (job == NULL)
found:
LASSERT(stats == job->js_jobstats);
- job->js_timestamp = ktime_get_real_seconds();
+ job->js_time_latest = ktime_get();
lprocfs_counter_add(job->js_stats, event, amount);
job_putref(job);
if (stats->ojs_hash == NULL)
return;
- lprocfs_job_cleanup(stats, -99);
+ lprocfs_job_cleanup(stats, true);
cfs_hash_putref(stats->ojs_hash);
stats->ojs_hash = NULL;
LASSERT(list_empty(&stats->ojs_list));
*
* job_stats:
* - job_id: dd.4854
- * snapshot_time: 1322494486
+ * snapshot_time: 1322494486.123456789
+ * start_time: 1322494476.012345678
+ * elapsed_time: 10.111111111
* open: { samples: 1, unit: reqs }
* close: { samples: 1, unit: reqs }
* mknod: { samples: 0, unit: reqs }
*
* job_stats:
* - job_id dd.4854
- * snapshot_time: 1322494602
+ * snapshot_time: 1322494602.123456789
+ * start_time: 1322494592.987654321
+ * elapsed_time: 9.135802468
* read: { samples: 0, unit: bytes, min: 0, max: 0, sum: 0 }
* write: { samples: 1, unit: bytes, min: 4096, max: 4096, sum: 4096 }
* setattr: { samples: 0, unit: reqs }
static int lprocfs_jobstats_seq_show(struct seq_file *p, void *v)
{
- struct job_stat *job = v;
- struct lprocfs_stats *s;
- struct lprocfs_counter ret;
- struct lprocfs_counter_header *cntr_header;
- int i;
+ struct job_stat *job = v;
+ struct lprocfs_stats *s;
+ struct lprocfs_counter ret;
+ struct lprocfs_counter_header *cntr_header;
+ int i;
if (v == SEQ_START_TOKEN) {
seq_printf(p, "job_stats:\n");
}
seq_putc(p, '\n');
- seq_printf(p, " %-16s %lld\n", "snapshot_time:", job->js_timestamp);
+ lprocfs_stats_header(p, job->js_time_latest, job->js_time_init, 16,
+ ":", true);
s = job->js_stats;
for (i = 0; i < s->ls_num; i++) {
jobid[len - 1] = 0;
if (strcmp(jobid, "clear") == 0) {
- lprocfs_job_cleanup(stats, -99);
+ lprocfs_job_cleanup(stats, true);
return len;
}
struct seq_file *seq = file->private_data;
struct obd_job_stats *stats = seq->private;
- lprocfs_job_cleanup(stats, stats->ojs_cleanup_interval);
+ lprocfs_job_cleanup(stats, false);
return lprocfs_seq_release(inode, file);
}
rwlock_init(&stats->ojs_lock);
stats->ojs_cntr_num = cntr_num;
stats->ojs_cntr_init_fn = init_fn;
- stats->ojs_cleanup_interval = 600; /* 10 mins by default */
- stats->ojs_last_cleanup = ktime_get_real_seconds();
+ /* Store 1/2 the actual interval, since we use that the most, and
+ * it is easier to work with.
+ */
+ stats->ojs_cleanup_interval = ktime_set(600 / 2, 0); /* default 10 min*/
+ stats->ojs_cleanup_last = ktime_get();
entry = lprocfs_add_simple(obd->obd_proc_entry, "job_stats", stats,
&lprocfs_jobstats_seq_fops);
struct obd_device *obd = container_of(kobj, struct obd_device,
obd_kset.kobj);
struct obd_job_stats *stats;
+ struct timespec64 ts;
stats = &obd->u.obt.obt_jobstats;
- return scnprintf(buf, PAGE_SIZE, "%d\n", stats->ojs_cleanup_interval);
+ ts = ktime_to_timespec64(stats->ojs_cleanup_interval);
+
+ return scnprintf(buf, PAGE_SIZE, "%lld\n", (long long)ts.tv_sec * 2);
}
EXPORT_SYMBOL(job_cleanup_interval_show);
if (rc)
return rc;
- stats->ojs_cleanup_interval = val;
- lprocfs_job_cleanup(stats, stats->ojs_cleanup_interval);
+ stats->ojs_cleanup_interval = ktime_set(val / 2, 0);
+ lprocfs_job_cleanup(stats, false);
+
return count;
}
EXPORT_SYMBOL(job_cleanup_interval_store);