Skip to content

Commit

Permalink
Move the C xenstore/console stubs to the test directory and out of th…
Browse files Browse the repository at this point in the history
…e main library
  • Loading branch information
David Scott committed Dec 7, 2012
1 parent 2761f01 commit fb314fb
Show file tree
Hide file tree
Showing 15 changed files with 585 additions and 128 deletions.
3 changes: 2 additions & 1 deletion _oasis
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ Library shared_memory_ring
Findlibname: shared-memory-ring
Modules: Ring
BuildDepends: cstruct, cstruct.syntax
CSources: ring_stubs.c, console.h, xenstore.h, barrier.h
CSources: ring_stubs.c, barrier.h

Library lwt_shared_memory_ring
CompiledObject: best
Expand All @@ -35,6 +35,7 @@ Executable ring_test
Custom: true
Install: false
BuildDepends: lwt, lwt.unix, shared-memory-ring, oUnit
CSources: old_ring_stubs.c, console.h, xenstore.h, barrier.h

Executable lwt_test
CompiledObject: best
Expand Down
9 changes: 8 additions & 1 deletion _tags
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# OASIS_START
# DO NOT EDIT (digest: e666e43e5d7ba3ab33d93f54b70ded55)
# DO NOT EDIT (digest: 44966d449a9ad0f75190dc5ba423e5d1)
# Ignore VCS directories, you can use the same kind of rule outside
# OASIS_START/STOP if you want to exclude directories that contains
# useless stuff for the build process
Expand Down Expand Up @@ -28,6 +28,7 @@
<lwt/*.ml{,i}>: pkg_cstruct
<lwt/*.ml{,i}>: pkg_cstruct.syntax
# Executable ring_test
<lib_test/ring_test.{native,byte}>: use_libring_test_stubs
<lib_test/ring_test.{native,byte}>: use_shared_memory_ring
<lib_test/ring_test.{native,byte}>: pkg_lwt
<lib_test/ring_test.{native,byte}>: pkg_lwt.unix
Expand All @@ -40,6 +41,12 @@
<lib_test/*.ml{,i}>: pkg_oUnit
<lib_test/*.ml{,i}>: pkg_cstruct
<lib_test/*.ml{,i}>: pkg_cstruct.syntax
"lib_test/old_ring_stubs.c": use_shared_memory_ring
"lib_test/old_ring_stubs.c": pkg_lwt
"lib_test/old_ring_stubs.c": pkg_lwt.unix
"lib_test/old_ring_stubs.c": pkg_oUnit
"lib_test/old_ring_stubs.c": pkg_cstruct
"lib_test/old_ring_stubs.c": pkg_cstruct.syntax
<lib_test/ring_test.{native,byte}>: custom
# Executable lwt_test
<lwt_test/lwt_test.{native,byte}>: use_lwt_shared_memory_ring
Expand Down
27 changes: 0 additions & 27 deletions lib/ring.ml
Original file line number Diff line number Diff line change
Expand Up @@ -369,30 +369,3 @@ module Console = struct
module Front = Pipe(Layout)
module Back = Pipe(Reverse(Layout))
end

(* Raw ring handling section *)
(* TODO both of these can be combined into one set of bindings now *)
module C_Console = struct
type t = buf
let of_buf t = t
external zero: t -> unit = "caml_console_ring_init"
external unsafe_write: t -> string -> int -> int = "caml_console_ring_write"
external unsafe_read: t -> string -> int -> int = "caml_console_ring_read"
module Back = struct
external unsafe_write : t -> string -> int -> int = "caml_console_back_ring_write"
external unsafe_read : t -> string -> int -> int = "caml_console_back_ring_read"
end
end

module C_Xenstore = struct
type t = buf
let of_buf t = t
external zero: t -> unit = "caml_xenstore_ring_init"
external unsafe_write: t -> string -> int -> int = "caml_xenstore_ring_write"
external unsafe_read: t -> string -> int -> int = "caml_xenstore_ring_read"
module Back = struct
external unsafe_write : t -> string -> int -> int = "caml_xenstore_back_ring_write"
external unsafe_read : t -> string -> int -> int = "caml_xenstore_back_ring_read"
end
end

22 changes: 0 additions & 22 deletions lib/ring.mli
Original file line number Diff line number Diff line change
Expand Up @@ -149,25 +149,3 @@ end

module Console : Bidirectional_byte_stream
module Xenstore : Bidirectional_byte_stream

module C_Console : sig
type t
external unsafe_write : t -> string -> int -> int = "caml_console_ring_write"
external unsafe_read : t -> string -> int -> int = "caml_console_ring_read"
module Back : sig
val unsafe_write : t -> string -> int -> int
val unsafe_read : t -> string -> int -> int
end
val of_buf : buf -> t
end

module C_Xenstore : sig
type t
external unsafe_write : t -> string -> int -> int = "caml_xenstore_ring_write"
external unsafe_read : t -> string -> int -> int = "caml_xenstore_ring_read"
module Back : sig
val unsafe_write : t -> string -> int -> int
val unsafe_read : t -> string -> int -> int
end
val of_buf : buf -> t
end
53 changes: 0 additions & 53 deletions lib/ring_stubs.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@
#include <caml/memory.h>
#include <caml/bigarray.h>

#include "console.h"
#include "xenstore.h"
#include "barrier.h"

#define xen_mb() mb()
Expand All @@ -35,57 +33,6 @@ extern void *memset(void *s, int c, size_t n);

#define PAGE_SIZE 4096

/* Raw ring operations
These have no request/response structs, just byte strings
*/

#define DEFINE_RAW_RING_OPS(xname,xtype,xin,xout) \
CAMLprim value \
caml_##xname##_ring_init(value v_ptr) \
{ \
memset((void *)Caml_ba_data_val(v_ptr), 0, PAGE_SIZE); \
return Val_unit; \
} \
CAMLprim value \
caml_##xname##_ring_write(value v_ptr, value v_str, value v_len) \
{ \
struct xtype *intf = (struct xtype *)Caml_ba_data_val(v_ptr); \
int sent = 0, len = Int_val(v_len); \
char *data = String_val(v_str); \
XENCONS_RING_IDX cons, prod; \
cons = intf->xout##_cons; \
prod = intf->xout##_prod; \
mb(); \
/* BUG_ON((prod - cons) > sizeof(intf->xout));*/ \
while ((sent < len) && ((prod - cons) < sizeof(intf->xout))) \
intf->xout[MASK_XENCONS_IDX(prod++, intf->xout)] = data[sent++]; \
wmb(); \
intf->xout##_prod = prod; \
return Val_int(sent); \
} \
CAMLprim value \
caml_##xname##_ring_read(value v_ptr, value v_str, value v_len) \
{ \
struct xtype *intf = (struct xtype *)Caml_ba_data_val(v_ptr); \
int pos=0, len = Int_val(v_len); \
char *data = String_val(v_str); \
XENCONS_RING_IDX cons, prod; \
cons = intf->xin##_cons; \
prod = intf->xin##_prod; \
mb(); \
/* BUG_ON((prod - cons) > sizeof(intf->xin));*/ \
while (cons != prod && pos < len) \
data[pos++] = intf->xin[MASK_XENCONS_IDX(cons++, intf->xin)]; \
mb(); \
intf->xin##_cons = cons; \
return Val_int(pos); \
}

DEFINE_RAW_RING_OPS(console,xencons_interface,in,out);
DEFINE_RAW_RING_OPS(console_back,xencons_interface,out,in);
DEFINE_RAW_RING_OPS(xenstore,xenstore_domain_interface,rsp,req);
DEFINE_RAW_RING_OPS(xenstore_back,xenstore_domain_interface,req,rsp);

/* Shared ring with request/response structs */

struct sring {
Expand Down
16 changes: 16 additions & 0 deletions lib_test/barrier.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/* Taken from include/minios/x86/os.h
*
* random collection of macros and definition
*/

#ifndef _BARRIER_H_
#define _BARRIER_H_

/* This is a barrier for the compiler only, NOT the processor! */
#define barrier() __asm__ __volatile__("": : :"memory")

#define mb() __asm__ __volatile__ ("mfence":::"memory")
#define rmb() __asm__ __volatile__ ("lfence":::"memory")
#define wmb() __asm__ __volatile__ ("sfence" ::: "memory") /* From CONFIG_UNORDERED_IO (linux) */

#endif /* _BARRIER_H_ */
File renamed without changes.
4 changes: 4 additions & 0 deletions lib_test/libring_test_stubs.clib
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# OASIS_START
# DO NOT EDIT (digest: 86f72fd814e3fd5b29a7347de47f1c81)
old_ring_stubs.o
# OASIS_STOP
Loading

0 comments on commit fb314fb

Please sign in to comment.