[PATCH] Fio's initial RTEMS port

2018-07-17 Thread dev . madaari
From: Udit kumar agarwal 

- Add rtems-specific config files.
- Constructors/Destructors being not supported by RTEMS, should be
  invoked as normal routines.
- Add documentation for RTEMS
- Update Makefile, os.h for RTEMS
---
 Makefile  |  11 ++-
 README|  29 ++
 cgroup.c  |   7 +-
 client.c  |   7 +-
 configure |   2 +
 crc/xxhash.h  |  15 
 engines/cpu.c |  14 ++-
 engines/falloc.c  |   7 +-
 engines/filecreate.c  |  14 ++-
 engines/ftruncate.c   |  14 ++-
 engines/glusterfs_async.c |   7 +-
 engines/glusterfs_sync.c  |  14 ++-
 engines/mmap.c|  14 ++-
 engines/net.c |  14 ++-
 engines/null.c|  14 ++-
 engines/sync.c|  14 ++-
 fio.c |   3 +
 fio.h |  10 ++-
 fio_sem.c |   6 ++
 gettime.c |  14 ++-
 init.c|  26 +-
 ioengines.c   |   2 +
 lib/prio_tree.c   |   7 +-
 options.c |   6 +-
 os/os-rtems.h |  70 +++
 os/os.h   |   3 +
 os/rtems/rtems-fio-wrap.h |  54 +++
 os/rtems/rtems-init.c | 225 ++
 oslib/inet_aton.c |   3 +-
 profiles/act.c|  14 ++-
 profiles/tiobench.c   |  14 ++-
 smalloc.c |  11 ++-
 stat.c|   6 ++
 t/arch.c  |   2 +
 34 files changed, 638 insertions(+), 35 deletions(-)
 create mode 100644 os/os-rtems.h
 create mode 100644 os/rtems/rtems-fio-wrap.h
 create mode 100644 os/rtems/rtems-init.c

diff --git a/Makefile b/Makefile
index 20d3ec1..e93f964 100644
--- a/Makefile
+++ b/Makefile
@@ -194,11 +194,20 @@ ifneq (,$(findstring CYGWIN,$(CONFIG_TARGET_OS)))
   LIBS  += -lpthread -lpsapi -lws2_32
   CFLAGS += -DPSAPI_VERSION=1 -Ios/windows/posix/include -Wno-format -static
 endif
+ifeq ($(CONFIG_TARGET_OS), RTEMS)
+  LDFLAGS += -B $(TOOL_PATH_PREFIX)/arm-rtems5/beagleboneblack/lib -specs 
bsp_specs -qrtems -Wl,--gc-sections
+  LIBS   += -Wl,-Bstatic -L. -lbsd -Wl,-Bdynamic -lm -lz
+  CFLAGS  += -I $(TOOL_PATH_PREFIX)/arm-rtems5/beagleboneblack/lib/include 
-ffunction-sections -fdata-sections -g -mcpu=cortex-a8 -fno-strict-aliasing 
-ffreestanding -fno-common -w -DHAVE_RTEMS_SCORE_CPUOPTS_H=1 -DHAVE_RTEMS_H=1 
-DHAVE_DLFCN_H=1 -DHAVE_RTEMS_PCI_H=1 -DHAVE_RTEMS_RTEMS_DEBUGGER_H=1
+endif
 
 OBJS := $(SOURCE:.c=.o)
 
 FIO_OBJS = $(OBJS) fio.o
 
+ifeq ($(CONFIG_TARGET_OS), RTEMS)
+  FIO_OBJS +=  os/rtems/rtems-init.o
+endif
+
 GFIO_OBJS = $(OBJS) gfio.o graph.o tickmarks.o ghelpers.o goptions.o gerror.o \
gclient.o gcompat.o cairo_text_helpers.o printing.o
 
@@ -462,7 +471,7 @@ t/time-test: $(T_TT_OBJS)
$(QUIET_LINK)$(CC) $(LDFLAGS) $(CFLAGS) -o $@ $(T_TT_OBJS) $(LIBS)
 
 clean: FORCE
-   @rm -f .depend $(FIO_OBJS) $(GFIO_OBJS) $(OBJS) $(T_OBJS) $(PROGS) 
$(T_PROGS) $(T_TEST_PROGS) core.* core gfio FIO-VERSION-FILE *.[do] lib/*.d 
oslib/*.[do] crc/*.d engines/*.[do] profiles/*.[do] t/*.[do] config-host.mak 
config-host.h y.tab.[ch] lex.yy.c exp/*.[do] lexer.h
+   @rm -f .depend $(FIO_OBJS) $(GFIO_OBJS) $(OBJS) $(T_OBJS) $(PROGS) 
$(T_PROGS) $(T_TEST_PROGS) core.* core gfio FIO-VERSION-FILE *.[do] lib/*.d 
oslib/*.[do] crc/*.d engines/*.[do] profiles/*.[do] t/*.[do] config-host.mak 
config-host.h y.tab.[ch] lex.yy.c exp/*.[do] lexer.h os/rtems/*.[do]
@rm -rf  doc/output
 
 distclean: clean FORCE
diff --git a/README b/README
index 38022bb..cbca933 100644
--- a/README
+++ b/README
@@ -192,6 +192,35 @@ https://github.com/mintty/mintty/issues/56 and
 
https://github.com/mintty/mintty/wiki/Tips#inputoutput-interaction-with-alien-programs
 for details).
 
+RTEMS
+~~~
+
+For RTEMS Toolchain generation::
+
+Toolchain, required for cross-compiling fio for desired architecture
+(like arm in this example) can be generated by using RTEMS Source Builder(RSB).
+
+Please note that fio's build for RTEMS has been tested with RSB version 
5(commit id:
+25f4db09c85a52fb1640a29f9bdc2de8c2768988), and it may not work with older 
versions.
+
+Moreover, For enabling POSIX support(required by fio), build the BSP using 
RTEMS v5 with
+--enable-posix option. After that, if needed(like for using SD card driver for 
BeagleBone Black)
+one may also need to build rtems-libbsd for the desired BSP.
+
+For Cross-compiling fio for RTEMS::
+
+Variable to be passed for toolchain path is TOOL_PATH_PREFIX, which in this 
case would be,
+
+ $ export TOOL_PATH_PREFIX=/home/uka_in/development/sandbox/5
+
+After setting up the variable, next step would be to configure and build fio 
as:
+
+ $ make clean
+ $ ./configure --cc=$TOOL_PATH_PREFIX/bin/arm-rtems5-gcc 
--disable-optimizations --extra-cflags=-O3
+ $ make CROSS_COMPILE=$TOOL_PATH_PREFIX/bin/arm-rtems5- V=1
+
+Refer to ticket #3429 https://devel.rtems.org/tic

[PATCH] Fio's initial RTEMS port

2018-07-17 Thread dev . madaari
Following IOengines are currently working on RTEMS:
 - psync, sync, vsync, filecreate, ftruncate, null

I've attached the patch in my following mail, please have a look.

Here's the corresponding ticket:https://devel.rtems.org/ticket/3429
Please note that i have also sent the patch to f...@vger.kernel.org, for their
review of mostly fio-specific part. 
___
devel mailing list
devel@rtems.org
http://lists.rtems.org/mailman/listinfo/devel


[PATCH v2] arm/beagle: Added TRNG based getentropy implementation

2018-03-16 Thread dev . madaari
From: Udit agarwal 

---
 bsps/arm/include/libcpu/am335x.h |  33 ++
 c/src/lib/libbsp/arm/beagle/Makefile.am  |   4 +-
 c/src/lib/libbsp/arm/beagle/dev/bbb_getentropy.c | 130 +++
 3 files changed, 166 insertions(+), 1 deletion(-)
 create mode 100644 c/src/lib/libbsp/arm/beagle/dev/bbb_getentropy.c

diff --git a/bsps/arm/include/libcpu/am335x.h b/bsps/arm/include/libcpu/am335x.h
index 367e97c..a6fb8b8 100644
--- a/bsps/arm/include/libcpu/am335x.h
+++ b/bsps/arm/include/libcpu/am335x.h
@@ -14,11 +14,17 @@
  * Modified by Ben Gras  to add lots
  * of beagleboard/beaglebone definitions, delete lpc32xx specific
  * ones, and merge with some other header files.
+ *
+ * Modified by Udit agarwal  to add true random
+ * number generating module definitions and TRNG register structure.
  */
 
 #if !defined(_AM335X_H_)
 #define _AM335X_H_
 
+/* For TRNG register definition */
+#include 
+
 /* Interrupt controller memory map */
 #define OMAP3_DM37XX_INTR_BASE 0x4820 /* INTCPS physical address */
 
@@ -701,4 +707,31 @@
 #define AM335X_CM_PER_OCPWP_L3_CLKSTCTRL_CLKACTIVITY_OCPWP_L4_GCLK 
(0x0020u)
 #define AM335X_I2C_INT_STOP_CONDITION AM335X_I2C_IRQSTATUS_BF
 
+/* TRNG Registers */
+/* TRNG base address */
+#define TRNG_BASE 0x4831
+/* Mask bits for trng clock status */
+#define AM335X_CLK_TRNG_BIT_MASK (0x3)
+/* Mask bits for output ready flag */
+#define TRNG_STATUS_RDY (1u <<  0)
+/* Mask bits for FRO related error */
+#define TRNG_STATUS_ERR (1u <<  1)
+/* Mask bits for clock status */
+#define TRNG_STATUS_CLK (1u << 31)
+/* enable module */
+#define AM335X_TRNG_ENABLE (1 << 10)
+
+/* TRNG module clock register */
+#define CM_PER_TRNG_CLKCTRL (AM335X_CM_PER_ADDR | (9 << 4))
+
+/* TRNG register structure */
+typedef struct {
+  uint64_t output; /* 00 */
+  uint32_t status; /* 08 */
+  uint32_t irq_en; /* 0c */
+  uint32_t status_clr; /* 10 */
+  uint32_t control;/* 14 */
+  uint32_t config; /* 18 */
+} am335x_trng_register;
+
 #endif
diff --git a/c/src/lib/libbsp/arm/beagle/Makefile.am 
b/c/src/lib/libbsp/arm/beagle/Makefile.am
index 8251660..c483dc4 100644
--- a/c/src/lib/libbsp/arm/beagle/Makefile.am
+++ b/c/src/lib/libbsp/arm/beagle/Makefile.am
@@ -40,7 +40,6 @@ libbsp_a_LIBADD =
 
 # Shared
 libbsp_a_SOURCES += ../../shared/bootcard.c
-libbsp_a_SOURCES += ../../shared/getentropy-cpucounter.c
 libbsp_a_SOURCES += ../../shared/src/bsp-fdt.c
 libbsp_a_SOURCES += ../../shared/bspclean.c
 libbsp_a_SOURCES += ../../shared/bspgetworkarea.c
@@ -88,6 +87,9 @@ libbsp_a_SOURCES += gpio/bbb-gpio.c
 #pwm
 libbsp_a_SOURCES += pwm/pwm.c
 
+#getentropy
+libbsp_a_SOURCES += dev/bbb_getentropy.c
+
 #RTC
 libbsp_a_SOURCES += rtc.c
 libbsp_a_SOURCES += ../../shared/tod.c
diff --git a/c/src/lib/libbsp/arm/beagle/dev/bbb_getentropy.c 
b/c/src/lib/libbsp/arm/beagle/dev/bbb_getentropy.c
new file mode 100644
index 000..b3ea681
--- /dev/null
+++ b/c/src/lib/libbsp/arm/beagle/dev/bbb_getentropy.c
@@ -0,0 +1,130 @@
+/**
+* @file
+*
+* @ingroup arm_beagle
+*
+* @brief Getentropy implementation on BeagleBone Black BSP
+*/
+
+/*
+* Copyright (c) 2018 Udit agarwal 
+* All rights reserved.
+*
+* Redistribution and use in source and binary forms, with or without
+* modification, are permitted provided that the following conditions
+* are met:
+* 1. Redistributions of source code must retain the above copyright
+*notice, this list of conditions and the following disclaimer.
+* 2. Redistributions in binary form must reproduce the above copyright
+*notice, this list of conditions and the following disclaimer in the
+*documentation and/or other materials provided with the distribution.
+*
+* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+* ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+* SUCH DAMAGE.
+*/
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+/* max refill 34 * 256 cycles */
+#define AM335X_TRNG_MAX_REFILL (34 << 16)
+/* min refill 33 * 64 cycles */
+#define AM335X_TRNG_MIN_REFILL (33 << 0)
+/* startup 33 * 256 cycles */
+#define AM335X_TRNG_STARTUP_CYCLES (33 << 16)
+
+static rtems_mutex am335x_trng_mutex =
+RTEMS_MUTEX_INITIALIZER("am335x_trng");
+
+/* maximun and minimum refill cycle sets the number of samples to be taken
+ * from FRO to generate random number */
+stat

[PATCH v2] arm/atsam: protect TRNG_GetRandData with mutex

2018-03-16 Thread dev . madaari
From: Udit agarwal 

---
 c/src/lib/libbsp/arm/atsam/startup/getentropy-trng.c | 7 +++
 1 file changed, 7 insertions(+)

diff --git a/c/src/lib/libbsp/arm/atsam/startup/getentropy-trng.c 
b/c/src/lib/libbsp/arm/atsam/startup/getentropy-trng.c
index 11e24dc..d3f1cf5 100644
--- a/c/src/lib/libbsp/arm/atsam/startup/getentropy-trng.c
+++ b/c/src/lib/libbsp/arm/atsam/startup/getentropy-trng.c
@@ -16,6 +16,10 @@
 #include 
 #include 
 #include 
+#include 
+
+static rtems_mutex atsam_trng_mutex =
+RTEMS_MUTEX_INITIALIZER("atsam_trng");
 
 static void atsam_trng_enable(void)
 {
@@ -25,6 +29,8 @@ static void atsam_trng_enable(void)
 
 int getentropy(void *ptr, size_t n)
 {
+   rtems_mutex_lock(&atsam_trng_mutex);
+
while (n > 0) {
uint32_t random;
size_t copy;
@@ -51,6 +57,7 @@ int getentropy(void *ptr, size_t n)
ptr += copy;
}
 
+   rtems_mutex_unlock(&atsam_trng_mutex);
return 0;
 }
 
-- 
1.9.1

___
devel mailing list
devel@rtems.org
http://lists.rtems.org/mailman/listinfo/devel