Spdk/lib/env_ocf
Amir Haroush 6984eff3c5 ocf: fix env_ticks_to_{msec,usec,nsec} precision & accuracy
- fix precision
 when one convert to seconds and then multiply
 we can have precision errors
 for example if one have 77ms, it will go to 0 when converted to seconds
 and then multiply that 0 by 1000 will return 0 instead of 77ms.

- fix mismatch nsec/usec
 nsec was multiplied by 1000*1000 while usec by 1000*1000*1000
 it should be the opposite.
 anyway the implementation had changed.

- implementation description
* env_ticks_to_msec: j / (tick_hz / 1000)
  this is exactly the same as (j * 1000) / tick_hz (eq #2).
  but this implementation (eq #2) can only handle 54b in j (before overflowing)
  because of the multiplication by 1000 (10b).
  with the correct implementation we use all 64b in j.
  we assume that tick_hz will be prefectly divisible by 1000 so we are ok.

* env_ticks_to_usec: j / (tick_hz / (1000 * 1000))
  same as in msec case, we use all 64b in j.
  here we assume that tick_hz is perfectly divisible by (1000 * 1000)
  i.e. we assume that CPU frequency is some multiple of 1MHz.

* env_ticks_to_nsec: (j * 1000) / (tick_hz / (1000 * 1000))
  in this case we can't assume that tick_hz is divisible by 10^9
  because there are many CPUs with 2.8GHz or 3.3GHz for example.
  so we multiply j by 1000
  this means that we can only handle correctly j up to 54b.
  (64b - 10b, 10b for the *1000 operation)

Signed-off-by: Amir Haroush <amir.haroush@huawei.com>
Signed-off-by: Shai Fultheim <shai.fultheim@huawei.com>
Change-Id: Ia8ea7f88b718df206fa0731e3f39f419ee922aa7
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/17078
Community-CI: Mellanox Build Bot
Tested-by: SPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: Jim Harris <james.r.harris@intel.com>
Reviewed-by: Ben Walker <benjamin.walker@intel.com>
2023-03-21 19:08:59 +00:00
..
.gitignore lib/mk: update OCF build. 2019-08-27 18:49:56 +00:00
Makefile update Intel copyright notices 2022-11-10 08:28:53 +00:00
mpool.c update Intel copyright notices 2022-11-10 08:28:53 +00:00
mpool.h update Intel copyright notices 2022-11-10 08:28:53 +00:00
ocf_env_headers.h update Intel copyright notices 2022-11-10 08:28:53 +00:00
ocf_env_list.h update Intel copyright notices 2022-11-10 08:28:53 +00:00
ocf_env.c update Intel copyright notices 2022-11-10 08:28:53 +00:00
ocf_env.h ocf: fix env_ticks_to_{msec,usec,nsec} precision & accuracy 2023-03-21 19:08:59 +00:00