diff mbox series

[v2] ceph: use ktime_to_timespec64() rather than jiffies_to_timespec64()

Message ID 20220307125235.440185-1-vshankar@redhat.com (mailing list archive)
State New, archived
Headers show
Series [v2] ceph: use ktime_to_timespec64() rather than jiffies_to_timespec64() | expand

Commit Message

Venky Shankar March 7, 2022, 12:52 p.m. UTC
Latencies are of type ktime_t, coverting from jiffies is incorrect.
Also, switch to "struct ceph_timespec" for r/w/m latencies.

Signed-off-by: Venky Shankar <vshankar@redhat.com>
---

v2:
  - rename to_ceph_timespec() to ktime_to_ceph_timespec()
  - use ceph_encode_timespec64() helper

 fs/ceph/metric.c | 19 +++++++++----------
 fs/ceph/metric.h | 11 ++++-------
 2 files changed, 13 insertions(+), 17 deletions(-)

Comments

Venky Shankar March 7, 2022, 12:59 p.m. UTC | #1
commit 73807b6905efa04cc01cd1223d5cc6ab57170f9e would also need a similar fix.

I'll send those...

On Mon, Mar 7, 2022 at 6:22 PM Venky Shankar <vshankar@redhat.com> wrote:
>
> Latencies are of type ktime_t, coverting from jiffies is incorrect.
> Also, switch to "struct ceph_timespec" for r/w/m latencies.
>
> Signed-off-by: Venky Shankar <vshankar@redhat.com>
> ---
>
> v2:
>   - rename to_ceph_timespec() to ktime_to_ceph_timespec()
>   - use ceph_encode_timespec64() helper
>
>  fs/ceph/metric.c | 19 +++++++++----------
>  fs/ceph/metric.h | 11 ++++-------
>  2 files changed, 13 insertions(+), 17 deletions(-)
>
> diff --git a/fs/ceph/metric.c b/fs/ceph/metric.c
> index 0fcba68f9a99..454d2c93208e 100644
> --- a/fs/ceph/metric.c
> +++ b/fs/ceph/metric.c
> @@ -8,6 +8,12 @@
>  #include "metric.h"
>  #include "mds_client.h"
>
> +static void ktime_to_ceph_timespec(struct ceph_timespec *ts, ktime_t val)
> +{
> +       struct timespec64 t = ktime_to_timespec64(val);
> +       ceph_encode_timespec64(ts, &t);
> +}
> +
>  static bool ceph_mdsc_send_metrics(struct ceph_mds_client *mdsc,
>                                    struct ceph_mds_session *s)
>  {
> @@ -26,7 +32,6 @@ static bool ceph_mdsc_send_metrics(struct ceph_mds_client *mdsc,
>         u64 nr_caps = atomic64_read(&m->total_caps);
>         u32 header_len = sizeof(struct ceph_metric_header);
>         struct ceph_msg *msg;
> -       struct timespec64 ts;
>         s64 sum;
>         s32 items = 0;
>         s32 len;
> @@ -63,9 +68,7 @@ static bool ceph_mdsc_send_metrics(struct ceph_mds_client *mdsc,
>         read->header.compat = 1;
>         read->header.data_len = cpu_to_le32(sizeof(*read) - header_len);
>         sum = m->metric[METRIC_READ].latency_sum;
> -       jiffies_to_timespec64(sum, &ts);
> -       read->sec = cpu_to_le32(ts.tv_sec);
> -       read->nsec = cpu_to_le32(ts.tv_nsec);
> +       ktime_to_ceph_timespec(&read->lat, sum);
>         items++;
>
>         /* encode the write latency metric */
> @@ -75,9 +78,7 @@ static bool ceph_mdsc_send_metrics(struct ceph_mds_client *mdsc,
>         write->header.compat = 1;
>         write->header.data_len = cpu_to_le32(sizeof(*write) - header_len);
>         sum = m->metric[METRIC_WRITE].latency_sum;
> -       jiffies_to_timespec64(sum, &ts);
> -       write->sec = cpu_to_le32(ts.tv_sec);
> -       write->nsec = cpu_to_le32(ts.tv_nsec);
> +       ktime_to_ceph_timespec(&write->lat, sum);
>         items++;
>
>         /* encode the metadata latency metric */
> @@ -87,9 +88,7 @@ static bool ceph_mdsc_send_metrics(struct ceph_mds_client *mdsc,
>         meta->header.compat = 1;
>         meta->header.data_len = cpu_to_le32(sizeof(*meta) - header_len);
>         sum = m->metric[METRIC_METADATA].latency_sum;
> -       jiffies_to_timespec64(sum, &ts);
> -       meta->sec = cpu_to_le32(ts.tv_sec);
> -       meta->nsec = cpu_to_le32(ts.tv_nsec);
> +       ktime_to_ceph_timespec(&meta->lat, sum);
>         items++;
>
>         /* encode the dentry lease metric */
> diff --git a/fs/ceph/metric.h b/fs/ceph/metric.h
> index bb45608181e7..5b2bb2897056 100644
> --- a/fs/ceph/metric.h
> +++ b/fs/ceph/metric.h
> @@ -2,7 +2,7 @@
>  #ifndef _FS_CEPH_MDS_METRIC_H
>  #define _FS_CEPH_MDS_METRIC_H
>
> -#include <linux/types.h>
> +#include <linux/ceph/types.h>
>  #include <linux/percpu_counter.h>
>  #include <linux/ktime.h>
>
> @@ -60,22 +60,19 @@ struct ceph_metric_cap {
>  /* metric read latency header */
>  struct ceph_metric_read_latency {
>         struct ceph_metric_header header;
> -       __le32 sec;
> -       __le32 nsec;
> +       struct ceph_timespec lat;
>  } __packed;
>
>  /* metric write latency header */
>  struct ceph_metric_write_latency {
>         struct ceph_metric_header header;
> -       __le32 sec;
> -       __le32 nsec;
> +       struct ceph_timespec lat;
>  } __packed;
>
>  /* metric metadata latency header */
>  struct ceph_metric_metadata_latency {
>         struct ceph_metric_header header;
> -       __le32 sec;
> -       __le32 nsec;
> +       struct ceph_timespec lat;
>  } __packed;
>
>  /* metric dentry lease header */
> --
> 2.27.0
>
Jeff Layton March 7, 2022, 1:09 p.m. UTC | #2
On Mon, 2022-03-07 at 18:29 +0530, Venky Shankar wrote:
> commit 73807b6905efa04cc01cd1223d5cc6ab57170f9e would also need a similar fix.
> 
> I'll send those...
> 

Ideally, send them as a set, and tell us which patches you want dropped
from testing before we merge them.

> On Mon, Mar 7, 2022 at 6:22 PM Venky Shankar <vshankar@redhat.com> wrote:
> > 
> > Latencies are of type ktime_t, coverting from jiffies is incorrect.
> > Also, switch to "struct ceph_timespec" for r/w/m latencies.
> > 
> > Signed-off-by: Venky Shankar <vshankar@redhat.com>
> > ---
> > 
> > v2:
> >   - rename to_ceph_timespec() to ktime_to_ceph_timespec()
> >   - use ceph_encode_timespec64() helper
> > 
> >  fs/ceph/metric.c | 19 +++++++++----------
> >  fs/ceph/metric.h | 11 ++++-------
> >  2 files changed, 13 insertions(+), 17 deletions(-)
> > 
> > diff --git a/fs/ceph/metric.c b/fs/ceph/metric.c
> > index 0fcba68f9a99..454d2c93208e 100644
> > --- a/fs/ceph/metric.c
> > +++ b/fs/ceph/metric.c
> > @@ -8,6 +8,12 @@
> >  #include "metric.h"
> >  #include "mds_client.h"
> > 
> > +static void ktime_to_ceph_timespec(struct ceph_timespec *ts, ktime_t val)
> > +{
> > +       struct timespec64 t = ktime_to_timespec64(val);
> > +       ceph_encode_timespec64(ts, &t);
> > +}
> > +
> >  static bool ceph_mdsc_send_metrics(struct ceph_mds_client *mdsc,
> >                                    struct ceph_mds_session *s)
> >  {
> > @@ -26,7 +32,6 @@ static bool ceph_mdsc_send_metrics(struct ceph_mds_client *mdsc,
> >         u64 nr_caps = atomic64_read(&m->total_caps);
> >         u32 header_len = sizeof(struct ceph_metric_header);
> >         struct ceph_msg *msg;
> > -       struct timespec64 ts;
> >         s64 sum;
> >         s32 items = 0;
> >         s32 len;
> > @@ -63,9 +68,7 @@ static bool ceph_mdsc_send_metrics(struct ceph_mds_client *mdsc,
> >         read->header.compat = 1;
> >         read->header.data_len = cpu_to_le32(sizeof(*read) - header_len);
> >         sum = m->metric[METRIC_READ].latency_sum;
> > -       jiffies_to_timespec64(sum, &ts);
> > -       read->sec = cpu_to_le32(ts.tv_sec);
> > -       read->nsec = cpu_to_le32(ts.tv_nsec);
> > +       ktime_to_ceph_timespec(&read->lat, sum);
> >         items++;
> > 
> >         /* encode the write latency metric */
> > @@ -75,9 +78,7 @@ static bool ceph_mdsc_send_metrics(struct ceph_mds_client *mdsc,
> >         write->header.compat = 1;
> >         write->header.data_len = cpu_to_le32(sizeof(*write) - header_len);
> >         sum = m->metric[METRIC_WRITE].latency_sum;
> > -       jiffies_to_timespec64(sum, &ts);
> > -       write->sec = cpu_to_le32(ts.tv_sec);
> > -       write->nsec = cpu_to_le32(ts.tv_nsec);
> > +       ktime_to_ceph_timespec(&write->lat, sum);
> >         items++;
> > 
> >         /* encode the metadata latency metric */
> > @@ -87,9 +88,7 @@ static bool ceph_mdsc_send_metrics(struct ceph_mds_client *mdsc,
> >         meta->header.compat = 1;
> >         meta->header.data_len = cpu_to_le32(sizeof(*meta) - header_len);
> >         sum = m->metric[METRIC_METADATA].latency_sum;
> > -       jiffies_to_timespec64(sum, &ts);
> > -       meta->sec = cpu_to_le32(ts.tv_sec);
> > -       meta->nsec = cpu_to_le32(ts.tv_nsec);
> > +       ktime_to_ceph_timespec(&meta->lat, sum);
> >         items++;
> > 
> >         /* encode the dentry lease metric */
> > diff --git a/fs/ceph/metric.h b/fs/ceph/metric.h
> > index bb45608181e7..5b2bb2897056 100644
> > --- a/fs/ceph/metric.h
> > +++ b/fs/ceph/metric.h
> > @@ -2,7 +2,7 @@
> >  #ifndef _FS_CEPH_MDS_METRIC_H
> >  #define _FS_CEPH_MDS_METRIC_H
> > 
> > -#include <linux/types.h>
> > +#include <linux/ceph/types.h>
> >  #include <linux/percpu_counter.h>
> >  #include <linux/ktime.h>
> > 
> > @@ -60,22 +60,19 @@ struct ceph_metric_cap {
> >  /* metric read latency header */
> >  struct ceph_metric_read_latency {
> >         struct ceph_metric_header header;
> > -       __le32 sec;
> > -       __le32 nsec;
> > +       struct ceph_timespec lat;
> >  } __packed;
> > 
> >  /* metric write latency header */
> >  struct ceph_metric_write_latency {
> >         struct ceph_metric_header header;
> > -       __le32 sec;
> > -       __le32 nsec;
> > +       struct ceph_timespec lat;
> >  } __packed;
> > 
> >  /* metric metadata latency header */
> >  struct ceph_metric_metadata_latency {
> >         struct ceph_metric_header header;
> > -       __le32 sec;
> > -       __le32 nsec;
> > +       struct ceph_timespec lat;
> >  } __packed;
> > 
> >  /* metric dentry lease header */
> > --
> > 2.27.0
> > 
> 
>
Venky Shankar March 7, 2022, 1:14 p.m. UTC | #3
On Mon, Mar 7, 2022 at 6:39 PM Jeff Layton <jlayton@redhat.com> wrote:
>
> On Mon, 2022-03-07 at 18:29 +0530, Venky Shankar wrote:
> > commit 73807b6905efa04cc01cd1223d5cc6ab57170f9e would also need a similar fix.
> >
> > I'll send those...
> >
>
> Ideally, send them as a set, and tell us which patches you want dropped
> from testing before we merge them.

Sure, works for me.

This change can be ignored.

>
> > On Mon, Mar 7, 2022 at 6:22 PM Venky Shankar <vshankar@redhat.com> wrote:
> > >
> > > Latencies are of type ktime_t, coverting from jiffies is incorrect.
> > > Also, switch to "struct ceph_timespec" for r/w/m latencies.
> > >
> > > Signed-off-by: Venky Shankar <vshankar@redhat.com>
> > > ---
> > >
> > > v2:
> > >   - rename to_ceph_timespec() to ktime_to_ceph_timespec()
> > >   - use ceph_encode_timespec64() helper
> > >
> > >  fs/ceph/metric.c | 19 +++++++++----------
> > >  fs/ceph/metric.h | 11 ++++-------
> > >  2 files changed, 13 insertions(+), 17 deletions(-)
> > >
> > > diff --git a/fs/ceph/metric.c b/fs/ceph/metric.c
> > > index 0fcba68f9a99..454d2c93208e 100644
> > > --- a/fs/ceph/metric.c
> > > +++ b/fs/ceph/metric.c
> > > @@ -8,6 +8,12 @@
> > >  #include "metric.h"
> > >  #include "mds_client.h"
> > >
> > > +static void ktime_to_ceph_timespec(struct ceph_timespec *ts, ktime_t val)
> > > +{
> > > +       struct timespec64 t = ktime_to_timespec64(val);
> > > +       ceph_encode_timespec64(ts, &t);
> > > +}
> > > +
> > >  static bool ceph_mdsc_send_metrics(struct ceph_mds_client *mdsc,
> > >                                    struct ceph_mds_session *s)
> > >  {
> > > @@ -26,7 +32,6 @@ static bool ceph_mdsc_send_metrics(struct ceph_mds_client *mdsc,
> > >         u64 nr_caps = atomic64_read(&m->total_caps);
> > >         u32 header_len = sizeof(struct ceph_metric_header);
> > >         struct ceph_msg *msg;
> > > -       struct timespec64 ts;
> > >         s64 sum;
> > >         s32 items = 0;
> > >         s32 len;
> > > @@ -63,9 +68,7 @@ static bool ceph_mdsc_send_metrics(struct ceph_mds_client *mdsc,
> > >         read->header.compat = 1;
> > >         read->header.data_len = cpu_to_le32(sizeof(*read) - header_len);
> > >         sum = m->metric[METRIC_READ].latency_sum;
> > > -       jiffies_to_timespec64(sum, &ts);
> > > -       read->sec = cpu_to_le32(ts.tv_sec);
> > > -       read->nsec = cpu_to_le32(ts.tv_nsec);
> > > +       ktime_to_ceph_timespec(&read->lat, sum);
> > >         items++;
> > >
> > >         /* encode the write latency metric */
> > > @@ -75,9 +78,7 @@ static bool ceph_mdsc_send_metrics(struct ceph_mds_client *mdsc,
> > >         write->header.compat = 1;
> > >         write->header.data_len = cpu_to_le32(sizeof(*write) - header_len);
> > >         sum = m->metric[METRIC_WRITE].latency_sum;
> > > -       jiffies_to_timespec64(sum, &ts);
> > > -       write->sec = cpu_to_le32(ts.tv_sec);
> > > -       write->nsec = cpu_to_le32(ts.tv_nsec);
> > > +       ktime_to_ceph_timespec(&write->lat, sum);
> > >         items++;
> > >
> > >         /* encode the metadata latency metric */
> > > @@ -87,9 +88,7 @@ static bool ceph_mdsc_send_metrics(struct ceph_mds_client *mdsc,
> > >         meta->header.compat = 1;
> > >         meta->header.data_len = cpu_to_le32(sizeof(*meta) - header_len);
> > >         sum = m->metric[METRIC_METADATA].latency_sum;
> > > -       jiffies_to_timespec64(sum, &ts);
> > > -       meta->sec = cpu_to_le32(ts.tv_sec);
> > > -       meta->nsec = cpu_to_le32(ts.tv_nsec);
> > > +       ktime_to_ceph_timespec(&meta->lat, sum);
> > >         items++;
> > >
> > >         /* encode the dentry lease metric */
> > > diff --git a/fs/ceph/metric.h b/fs/ceph/metric.h
> > > index bb45608181e7..5b2bb2897056 100644
> > > --- a/fs/ceph/metric.h
> > > +++ b/fs/ceph/metric.h
> > > @@ -2,7 +2,7 @@
> > >  #ifndef _FS_CEPH_MDS_METRIC_H
> > >  #define _FS_CEPH_MDS_METRIC_H
> > >
> > > -#include <linux/types.h>
> > > +#include <linux/ceph/types.h>
> > >  #include <linux/percpu_counter.h>
> > >  #include <linux/ktime.h>
> > >
> > > @@ -60,22 +60,19 @@ struct ceph_metric_cap {
> > >  /* metric read latency header */
> > >  struct ceph_metric_read_latency {
> > >         struct ceph_metric_header header;
> > > -       __le32 sec;
> > > -       __le32 nsec;
> > > +       struct ceph_timespec lat;
> > >  } __packed;
> > >
> > >  /* metric write latency header */
> > >  struct ceph_metric_write_latency {
> > >         struct ceph_metric_header header;
> > > -       __le32 sec;
> > > -       __le32 nsec;
> > > +       struct ceph_timespec lat;
> > >  } __packed;
> > >
> > >  /* metric metadata latency header */
> > >  struct ceph_metric_metadata_latency {
> > >         struct ceph_metric_header header;
> > > -       __le32 sec;
> > > -       __le32 nsec;
> > > +       struct ceph_timespec lat;
> > >  } __packed;
> > >
> > >  /* metric dentry lease header */
> > > --
> > > 2.27.0
> > >
> >
> >
>
> --
> Jeff Layton <jlayton@redhat.com>
>
diff mbox series

Patch

diff --git a/fs/ceph/metric.c b/fs/ceph/metric.c
index 0fcba68f9a99..454d2c93208e 100644
--- a/fs/ceph/metric.c
+++ b/fs/ceph/metric.c
@@ -8,6 +8,12 @@ 
 #include "metric.h"
 #include "mds_client.h"
 
+static void ktime_to_ceph_timespec(struct ceph_timespec *ts, ktime_t val)
+{
+	struct timespec64 t = ktime_to_timespec64(val);
+	ceph_encode_timespec64(ts, &t);
+}
+
 static bool ceph_mdsc_send_metrics(struct ceph_mds_client *mdsc,
 				   struct ceph_mds_session *s)
 {
@@ -26,7 +32,6 @@  static bool ceph_mdsc_send_metrics(struct ceph_mds_client *mdsc,
 	u64 nr_caps = atomic64_read(&m->total_caps);
 	u32 header_len = sizeof(struct ceph_metric_header);
 	struct ceph_msg *msg;
-	struct timespec64 ts;
 	s64 sum;
 	s32 items = 0;
 	s32 len;
@@ -63,9 +68,7 @@  static bool ceph_mdsc_send_metrics(struct ceph_mds_client *mdsc,
 	read->header.compat = 1;
 	read->header.data_len = cpu_to_le32(sizeof(*read) - header_len);
 	sum = m->metric[METRIC_READ].latency_sum;
-	jiffies_to_timespec64(sum, &ts);
-	read->sec = cpu_to_le32(ts.tv_sec);
-	read->nsec = cpu_to_le32(ts.tv_nsec);
+	ktime_to_ceph_timespec(&read->lat, sum);
 	items++;
 
 	/* encode the write latency metric */
@@ -75,9 +78,7 @@  static bool ceph_mdsc_send_metrics(struct ceph_mds_client *mdsc,
 	write->header.compat = 1;
 	write->header.data_len = cpu_to_le32(sizeof(*write) - header_len);
 	sum = m->metric[METRIC_WRITE].latency_sum;
-	jiffies_to_timespec64(sum, &ts);
-	write->sec = cpu_to_le32(ts.tv_sec);
-	write->nsec = cpu_to_le32(ts.tv_nsec);
+	ktime_to_ceph_timespec(&write->lat, sum);
 	items++;
 
 	/* encode the metadata latency metric */
@@ -87,9 +88,7 @@  static bool ceph_mdsc_send_metrics(struct ceph_mds_client *mdsc,
 	meta->header.compat = 1;
 	meta->header.data_len = cpu_to_le32(sizeof(*meta) - header_len);
 	sum = m->metric[METRIC_METADATA].latency_sum;
-	jiffies_to_timespec64(sum, &ts);
-	meta->sec = cpu_to_le32(ts.tv_sec);
-	meta->nsec = cpu_to_le32(ts.tv_nsec);
+	ktime_to_ceph_timespec(&meta->lat, sum);
 	items++;
 
 	/* encode the dentry lease metric */
diff --git a/fs/ceph/metric.h b/fs/ceph/metric.h
index bb45608181e7..5b2bb2897056 100644
--- a/fs/ceph/metric.h
+++ b/fs/ceph/metric.h
@@ -2,7 +2,7 @@ 
 #ifndef _FS_CEPH_MDS_METRIC_H
 #define _FS_CEPH_MDS_METRIC_H
 
-#include <linux/types.h>
+#include <linux/ceph/types.h>
 #include <linux/percpu_counter.h>
 #include <linux/ktime.h>
 
@@ -60,22 +60,19 @@  struct ceph_metric_cap {
 /* metric read latency header */
 struct ceph_metric_read_latency {
 	struct ceph_metric_header header;
-	__le32 sec;
-	__le32 nsec;
+	struct ceph_timespec lat;
 } __packed;
 
 /* metric write latency header */
 struct ceph_metric_write_latency {
 	struct ceph_metric_header header;
-	__le32 sec;
-	__le32 nsec;
+	struct ceph_timespec lat;
 } __packed;
 
 /* metric metadata latency header */
 struct ceph_metric_metadata_latency {
 	struct ceph_metric_header header;
-	__le32 sec;
-	__le32 nsec;
+	struct ceph_timespec lat;
 } __packed;
 
 /* metric dentry lease header */