qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Qemu-devel] [RFC PATCH 10/14] pc-bios/s390-ccw: Add timer code for the


From: Thomas Huth
Subject: [Qemu-devel] [RFC PATCH 10/14] pc-bios/s390-ccw: Add timer code for the libnet
Date: Tue, 27 Jun 2017 13:48:16 +0200

The libnet expects certain timer functions to exist, so that it
is able to deal with timeouts etc.
This patch implements these timer functions via the STORE CLOCK (stck)
CPU instruction.

Signed-off-by: Thomas Huth <address@hidden>
---
 pc-bios/s390-ccw/libnet/Makefile |  2 +-
 pc-bios/s390-ccw/libnet/timer.c  | 40 ++++++++++++++++++++++++++++++++++++++++
 2 files changed, 41 insertions(+), 1 deletion(-)
 create mode 100644 pc-bios/s390-ccw/libnet/timer.c

diff --git a/pc-bios/s390-ccw/libnet/Makefile b/pc-bios/s390-ccw/libnet/Makefile
index 72e12d7..c8235f3 100644
--- a/pc-bios/s390-ccw/libnet/Makefile
+++ b/pc-bios/s390-ccw/libnet/Makefile
@@ -24,7 +24,7 @@ QEMU_CFLAGS += $(call cc-option, $(QEMU_CFLAGS), 
-fno-stack-protector)
 LDFLAGS += -Wl,-pie -nostdlib
 
 SRCS = ethernet.c ipv4.c udp.c tcp.c dns.c dhcp.c tftp.c \
-       ipv6.c dhcpv6.c icmpv6.c ndp.c netload.c args.c
+       ipv6.c dhcpv6.c icmpv6.c ndp.c netload.c args.c timer.c
 
 OBJS = $(SRCS:%.c=%.o)
 
diff --git a/pc-bios/s390-ccw/libnet/timer.c b/pc-bios/s390-ccw/libnet/timer.c
new file mode 100644
index 0000000..ddbd7a2
--- /dev/null
+++ b/pc-bios/s390-ccw/libnet/timer.c
@@ -0,0 +1,40 @@
+/*
+ * Timer functions for libnet
+ *
+ * Copyright 2017 Thomas Huth, Red Hat Inc.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; either version 2 of the License, or (at your
+ * option) any later version.
+ */
+
+#include <stdint.h>
+#include "time.h"
+
+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 incrememented each microsecond */
+       return (clk >> (63 - 51)) / 1000;
+}
+
+void set_timer(int val)
+{
+       dest_timer = get_timer_ms() + val;
+}
+
+int get_timer(void)
+{
+       return dest_timer - get_timer_ms();
+}
+
+int get_sec_ticks(void)
+{
+       return 1000;    /* number of ticks in 1 second */
+}
-- 
1.8.3.1




reply via email to

[Prev in Thread] Current Thread [Next in Thread]