[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 02/14] pc-bios: s390x: Consolidate timing functions into time.h
From: |
Cornelia Huck |
Subject: |
[PULL 02/14] pc-bios: s390x: Consolidate timing functions into time.h |
Date: |
Fri, 3 Jul 2020 12:06:38 +0200 |
From: Janosch Frank <frankja@linux.ibm.com>
Let's consolidate timing related functions into one header.
Signed-off-by: Janosch Frank <frankja@linux.ibm.com>
Acked-by: Thomas Huth <thuth@redhat.com>
Reviewed-by: David Hildenbrand <david@redhat.com>
Message-Id: <20200624075226.92728-3-frankja@linux.ibm.com>
Signed-off-by: Thomas Huth <thuth@redhat.com>
---
pc-bios/s390-ccw/menu.c | 1 +
pc-bios/s390-ccw/netmain.c | 15 +++------------
pc-bios/s390-ccw/s390-ccw.h | 8 ++++----
pc-bios/s390-ccw/s390-time.h | 23 +++++++++++++++++++++++
pc-bios/s390-ccw/virtio-net.c | 1 +
pc-bios/s390-ccw/virtio-scsi.c | 1 +
pc-bios/s390-ccw/virtio.c | 18 +++---------------
7 files changed, 36 insertions(+), 31 deletions(-)
create mode 100644 pc-bios/s390-ccw/s390-time.h
diff --git a/pc-bios/s390-ccw/menu.c b/pc-bios/s390-ccw/menu.c
index ce3815b2010d..de8260a5d6cf 100644
--- a/pc-bios/s390-ccw/menu.c
+++ b/pc-bios/s390-ccw/menu.c
@@ -12,6 +12,7 @@
#include "libc.h"
#include "s390-ccw.h"
#include "sclp.h"
+#include "s390-time.h"
#define KEYCODE_NO_INP '\0'
#define KEYCODE_ESCAPE '\033'
diff --git a/pc-bios/s390-ccw/netmain.c b/pc-bios/s390-ccw/netmain.c
index 309ffa30d992..f1ee63577ad7 100644
--- a/pc-bios/s390-ccw/netmain.c
+++ b/pc-bios/s390-ccw/netmain.c
@@ -35,6 +35,7 @@
#include "s390-ccw.h"
#include "cio.h"
#include "virtio.h"
+#include "s390-time.h"
#define DEFAULT_BOOT_RETRIES 10
#define DEFAULT_TFTP_RETRIES 20
@@ -57,24 +58,14 @@ static SubChannelId net_schid = { .one = 1 };
static uint8_t mac[6];
static uint64_t dest_timer;
-static uint64_t get_timer_ms(void)
-{
- uint64_t clk;
-
- asm volatile(" stck %0 " : : "Q"(clk) : "memory");
-
- /* Bit 51 is incremented each microsecond */
- return (clk >> (63 - 51)) / 1000;
-}
-
void set_timer(int val)
{
- dest_timer = get_timer_ms() + val;
+ dest_timer = get_time_ms() + val;
}
int get_timer(void)
{
- return dest_timer - get_timer_ms();
+ return dest_timer - get_time_ms();
}
int get_sec_ticks(void)
diff --git a/pc-bios/s390-ccw/s390-ccw.h b/pc-bios/s390-ccw/s390-ccw.h
index 21f27e79906e..fae1de363fb4 100644
--- a/pc-bios/s390-ccw/s390-ccw.h
+++ b/pc-bios/s390-ccw/s390-ccw.h
@@ -74,8 +74,6 @@ unsigned long virtio_load_direct(ulong rec_list1, ulong
rec_list2,
bool virtio_is_supported(SubChannelId schid);
void virtio_blk_setup_device(SubChannelId schid);
int virtio_read(ulong sector, void *load_addr);
-u64 get_clock(void);
-ulong get_second(void);
/* bootmap.c */
void zipl_load(void);
@@ -153,11 +151,13 @@ static inline void yield(void)
#define MAX_SECTOR_SIZE 4096
+#include "s390-time.h"
+
static inline void sleep(unsigned int seconds)
{
- ulong target = get_second() + seconds;
+ ulong target = get_time_seconds() + seconds;
- while (get_second() < target) {
+ while (get_time_seconds() < target) {
yield();
}
}
diff --git a/pc-bios/s390-ccw/s390-time.h b/pc-bios/s390-ccw/s390-time.h
new file mode 100644
index 000000000000..ed6d98237185
--- /dev/null
+++ b/pc-bios/s390-ccw/s390-time.h
@@ -0,0 +1,23 @@
+#ifndef TIME_H
+#define TIME_H
+
+static inline u64 get_clock(void)
+{
+ u64 r;
+
+ asm volatile("stck %0" : "=Q" (r) : : "cc");
+ return r;
+}
+
+static inline u64 get_time_ms(void)
+{
+ /* Bit 51 is incremented each microsecond */
+ return (get_clock() >> 12) / 1000;
+}
+
+static inline u64 get_time_seconds(void)
+{
+ return get_time_ms() / 1000;
+}
+
+#endif
diff --git a/pc-bios/s390-ccw/virtio-net.c b/pc-bios/s390-ccw/virtio-net.c
index ff7f4dad2597..a13f3b6fb9b4 100644
--- a/pc-bios/s390-ccw/virtio-net.c
+++ b/pc-bios/s390-ccw/virtio-net.c
@@ -19,6 +19,7 @@
#include <ethernet.h>
#include "s390-ccw.h"
#include "virtio.h"
+#include "s390-time.h"
#ifndef DEBUG_VIRTIO_NET
#define DEBUG_VIRTIO_NET 0
diff --git a/pc-bios/s390-ccw/virtio-scsi.c b/pc-bios/s390-ccw/virtio-scsi.c
index 4fe4b9d261a6..7bf0be4ffa31 100644
--- a/pc-bios/s390-ccw/virtio-scsi.c
+++ b/pc-bios/s390-ccw/virtio-scsi.c
@@ -14,6 +14,7 @@
#include "virtio.h"
#include "scsi.h"
#include "virtio-scsi.h"
+#include "s390-time.h"
static ScsiDevice default_scsi_device;
static VirtioScsiCmdReq req;
diff --git a/pc-bios/s390-ccw/virtio.c b/pc-bios/s390-ccw/virtio.c
index fb40ca982853..ab49840db853 100644
--- a/pc-bios/s390-ccw/virtio.c
+++ b/pc-bios/s390-ccw/virtio.c
@@ -15,6 +15,7 @@
#include "virtio-scsi.h"
#include "bswap.h"
#include "helper.h"
+#include "s390-time.h"
#define VRING_WAIT_REPLY_TIMEOUT 30
@@ -157,19 +158,6 @@ void vring_send_buf(VRing *vr, void *p, int len, int flags)
}
}
-u64 get_clock(void)
-{
- u64 r;
-
- asm volatile("stck %0" : "=Q" (r) : : "cc");
- return r;
-}
-
-ulong get_second(void)
-{
- return (get_clock() >> 12) / 1000000;
-}
-
int vr_poll(VRing *vr)
{
if (vr->used->idx == vr->used_idx) {
@@ -194,7 +182,7 @@ int vr_poll(VRing *vr)
*/
int vring_wait_reply(void)
{
- ulong target_second = get_second() + vdev.wait_reply_timeout;
+ ulong target_second = get_time_seconds() + vdev.wait_reply_timeout;
/* Wait for any queue to be updated by the host */
do {
@@ -207,7 +195,7 @@ int vring_wait_reply(void)
if (r) {
return 0;
}
- } while (!vdev.wait_reply_timeout || (get_second() < target_second));
+ } while (!vdev.wait_reply_timeout || (get_time_seconds() < target_second));
return 1;
}
--
2.25.4
- [PULL 00/14] s390x update, Cornelia Huck, 2020/07/03
- [PULL 01/14] pc-bios: s390x: cio.c cleanup and compile fix, Cornelia Huck, 2020/07/03
- [PULL 02/14] pc-bios: s390x: Consolidate timing functions into time.h,
Cornelia Huck <=
- [PULL 03/14] pc-bios: s390x: Move sleep and yield to helper.h, Cornelia Huck, 2020/07/03
- [PULL 04/14] pc-bios: s390x: Get rid of magic offsets into the lowcore, Cornelia Huck, 2020/07/03
- [PULL 05/14] pc-bios: s390x: Rename PSW_MASK_ZMODE to PSW_MASK_64, Cornelia Huck, 2020/07/03
- [PULL 06/14] pc-bios: s390x: Use PSW masks where possible and introduce PSW_MASK_SHORT_ADDR, Cornelia Huck, 2020/07/03
- [PULL 07/14] pc-bios: s390x: Move panic() into header and add infinite loop, Cornelia Huck, 2020/07/03
- [PULL 08/14] pc-bios: s390x: Use ebcdic2ascii table, Cornelia Huck, 2020/07/03
- [PULL 09/14] pc-bios: s390x: Make u32 ptr check explicit, Cornelia Huck, 2020/07/03
- [PULL 10/14] pc-bios/s390-ccw: Generate and include dependency files in the Makefile, Cornelia Huck, 2020/07/03
- [PULL 11/14] pc-bios/s390: Update s390-ccw bios binaries with the latest changes, Cornelia Huck, 2020/07/03
- [PULL 12/14] target/s390x: Fix SQXBR, Cornelia Huck, 2020/07/03