Permalink
Browse files

gdev: updated scheduler

gdev: temporarily disabled garbage collection due to shared memory bugs
gdev: added gbarrier()
  • Loading branch information...
1 parent 5709200 commit 30bc41b326727e9f392671fe7bb22edd527a0bdb Shinpei Kato committed Jan 11, 2012
View
@@ -881,6 +881,15 @@ int gsync(struct gdev_handle *h, uint32_t id, struct gdev_time *timeout)
}
/**
+ * gbarrier():
+ * explicitly barrier the memory.
+ */
+int gbarrier(struct gdev_handle *h)
+{
+ return gdev_barrier(h->ctx);
+}
+
+/**
* gquery():
* query the device-specific information.
*/
View
@@ -59,6 +59,7 @@ int gmemcpy_user_from_device_async(Ghandle h, void *dst_buf, uint64_t src_addr,
int gmemcpy_in_device(Ghandle h, uint64_t dst_addr, uint64_t src_addr, uint64_t size);
int glaunch(Ghandle h, struct gdev_kernel *kernel, uint32_t *id);
int gsync(Ghandle h, uint32_t id, struct gdev_time *timeout);
+int gbarrier(Ghandle h);
int gquery(Ghandle h, uint32_t type, uint64_t *result);
int gtune(Ghandle h, uint32_t type, uint32_t value);
int gshmget(Ghandle h, int key, uint64_t size, int flags);
View
@@ -52,6 +52,7 @@ void gdev_write32(gdev_mem_t *mem, uint64_t addr, uint32_t val);
int gdev_read(gdev_mem_t *mem, void *buf, uint64_t addr, uint32_t size);
int gdev_write(gdev_mem_t *mem, uint64_t addr, const void *buf, uint32_t size);
int gdev_poll(gdev_ctx_t *ctx, uint32_t seq, struct gdev_time *timeout);
+int gdev_barrier(struct gdev_ctx *ctx);
int gdev_query(struct gdev_device *gdev, uint32_t type, uint64_t *result);
/**
@@ -43,12 +43,13 @@
#define GDEV_IOCTL_GMEMCPY_IN_DEVICE 0x108
#define GDEV_IOCTL_GLAUNCH 0x109
#define GDEV_IOCTL_GSYNC 0x110
-#define GDEV_IOCTL_GQUERY 0x111
-#define GDEV_IOCTL_GTUNE 0x112
-#define GDEV_IOCTL_GSHMGET 0x113
-#define GDEV_IOCTL_GSHMAT 0x114
-#define GDEV_IOCTL_GSHMDT 0x115
-#define GDEV_IOCTL_GSHMCTL 0x116
+#define GDEV_IOCTL_GBARRIER 0x111
+#define GDEV_IOCTL_GQUERY 0x112
+#define GDEV_IOCTL_GTUNE 0x113
+#define GDEV_IOCTL_GSHMGET 0x114
+#define GDEV_IOCTL_GSHMAT 0x115
+#define GDEV_IOCTL_GSHMDT 0x116
+#define GDEV_IOCTL_GSHMCTL 0x117
struct gdev_ioctl_mem {
uint64_t addr;
@@ -35,6 +35,10 @@
#include "gdev_system.h"
#include "gdev_time.h"
+#ifdef GDEV_SCHED_MRQ
+#define GDEV_NVIDIA_MEMCPY_PCOPY
+#endif
+
#define GDEV_SUBCH_NV_COMPUTE GDEV_SUBCH_COMPUTE
#ifndef GDEV_NVIDIA_MEMCPY_PCOPY
#define GDEV_SUBCH_NV_M2MF GDEV_SUBCH_MEMCPY
@@ -143,7 +143,7 @@ int gdev_poll(struct gdev_ctx *ctx, uint32_t seq, struct gdev_time *timeout)
struct gdev_compute *compute = gdev->compute;
gdev_time_stamp(&time_start);
- gdev_time_ms(&time_relax, 100); /* relax polling when 100 ms elapsed. */
+ gdev_time_ms(&time_relax, 1000); /* relax polling when 1000 ms elapsed. */
while (seq != compute->fence_read(ctx, seq)) {
gdev_time_stamp(&time_now);
@@ -162,6 +162,21 @@ int gdev_poll(struct gdev_ctx *ctx, uint32_t seq, struct gdev_time *timeout)
return 0;
}
+/* barrier memory by blocking. */
+int gdev_barrier(struct gdev_ctx *ctx)
+{
+ struct gdev_vas *vas = ctx->vas;
+ struct gdev_device *gdev = vas->gdev;
+ struct gdev_compute *compute = gdev->compute;
+ uint32_t seq = 0; /* 0 is a special sequence for barrier. */
+
+ compute->membar(ctx);
+ compute->fence_write(ctx, GDEV_SUBCH_COMPUTE, seq);
+ while (seq != compute->fence_read(ctx, seq));
+
+ return 0;
+}
+
/* query device-specific information. */
int gdev_query(struct gdev_device *gdev, uint32_t type, uint64_t *result)
{
@@ -206,17 +206,20 @@ void gdev_mem_free(struct gdev_mem *mem)
/* garbage collection: free all memory left in heap. */
void gdev_mem_gc(struct gdev_vas *vas)
{
+#ifdef GDEV_GARBAGE_COLLECTION_SUPPORT
struct gdev_mem *mem;
/* device memory. */
gdev_list_for_each (mem, &vas->mem_list, list_entry_heap) {
+ GDEV_PRINT("Garbage Collect 0x%llx\n", mem->addr);
gdev_mem_free(mem);
}
/* host DMA memory. */
gdev_list_for_each (mem, &vas->dma_mem_list, list_entry_heap) {
gdev_mem_free(mem);
}
+#endif
}
/* look up the memory object allocated at the specified address. */
@@ -157,8 +157,6 @@ int gdev_shm_create(struct gdev_device *gdev, struct gdev_vas *vas, int key, uin
int gdev_shm_destroy_mark(struct gdev_device *gdev, struct gdev_mem *owner)
{
gdev_mutex_lock(&owner->shm->mutex);
- /* delete the current owner. */
- gdev_list_del(&owner->list_entry_shm);
/* find the new owner (could be NULL). */
gdev_shm_owners[owner->shm->id] =
gdev_list_container(gdev_list_head(&owner->shm->mem_list));
View
@@ -172,16 +172,24 @@ static void __gdev_dequeue_memory(struct gdev_sched_entity *se)
/**
* scheduling policy files.
*/
+#include "gdev_vsched_band.c"
#include "gdev_vsched_credit.c"
-#include "gdev_vsched_crod.c"
+#include "gdev_vsched_cnods.c"
+#include "gdev_vsched_fifo.c"
-#define GDEV_VSCHED_POLICY_CREDIT
-//#define GDEV_VSCHED_POLICY_CROD
+#define GDEV_VSCHED_POLICY_BAND
+//#define GDEV_VSCHED_POLICY_CREDIT
+//#define GDEV_VSCHED_POLICY_CNODS
+//#define GDEV_VSCHED_POLICY_FIFO
-#if defined(GDEV_VSCHED_POLICY_CREDIT)
+#if defined(GDEV_VSCHED_POLICY_BAND)
+struct gdev_vsched_policy *gdev_vsched = &gdev_vsched_band;
+#elif defined(GDEV_VSCHED_POLICY_CREDIT)
struct gdev_vsched_policy *gdev_vsched = &gdev_vsched_credit;
-#elif defined(GDEV_VSCHED_POLICY_CROD)
-struct gdev_vsched_policy *gdev_vsched = &gdev_vsched_crod;
+#elif defined(GDEV_VSCHED_POLICY_CNODS)
+struct gdev_vsched_policy *gdev_vsched = &gdev_vsched_cnods;
+#elif defined(GDEV_VSCHED_POLICY_FIFO)
+struct gdev_vsched_policy *gdev_vsched = &gdev_vsched_fifo;
#endif
/**
@@ -259,10 +267,6 @@ void gdev_select_next_compute(struct gdev_device *gdev)
gdev->current_com = (void*)se;
gdev_unlock(&gdev->sched_com_lock);
- printk("gdev%d->credit_com = %s%lu\n", gdev->id,
- gdev->credit_com.neg ? "-" : "",
- gdev_time_to_us(&gdev->credit_com));
-
/* select the next device to be scheduled. */
next = gdev_vsched->select_next_compute(gdev);
if (!next)
@@ -280,7 +284,7 @@ void gdev_select_next_compute(struct gdev_device *gdev)
__gdev_dequeue_compute(se);
gdev_unlock(&next->sched_com_lock);
- while (gdev_sched_wakeup(se->task) < 0) {
+ if (gdev_sched_wakeup(se->task) < 0) {
GDEV_PRINT("Failed to wake up context %d\n", se->ctx->cid);
}
}
@@ -306,6 +310,11 @@ void gdev_schedule_memory(struct gdev_sched_entity *se)
{
struct gdev_device *gdev = se->gdev;
+#ifndef GDEV_SCHED_MRQ
+ gdev_schedule_compute(se);
+ return;
+#endif
+
resched:
/* algorithm-specific virtual device scheduler. */
gdev_vsched->schedule_memory(se);
@@ -345,6 +354,11 @@ void gdev_select_next_memory(struct gdev_device *gdev)
struct gdev_device *next;
struct gdev_time now, exec;
+#ifndef GDEV_SCHED_MRQ
+ gdev_select_next_compute(gdev);
+ return;
+#endif
+
gdev_lock(&gdev->sched_mem_lock);
se = (struct gdev_sched_entity *)gdev->current_mem;
if (!se) {
@@ -374,10 +388,6 @@ void gdev_select_next_memory(struct gdev_device *gdev)
gdev->current_mem = (void*)se;
gdev_unlock(&gdev->sched_mem_lock);
- printk("gdev%d->credit_mem = %s%lu\n", gdev->id,
- gdev->credit_mem.neg ? "-" : "",
- gdev_time_to_us(&gdev->credit_mem));
-
/* select the next device to be scheduled. */
next = gdev_vsched->select_next_memory(gdev);
if (!next)
@@ -411,5 +421,7 @@ void gdev_select_next_memory(struct gdev_device *gdev)
*/
void gdev_replenish_credit_memory(struct gdev_device *gdev)
{
+#ifdef GDEV_SCHED_MRQ
gdev_vsched->replenish_memory(gdev);
+#endif
}
View
@@ -33,6 +33,13 @@
#include "gdev_time.h"
/**
+ * Queueing methods:
+ * SGQ: Single Device Queue
+ * MRQ: Multiple Resource Queues
+ */
+#define GDEV_SCHED_SGQ /*GDEV_SCHED_MRQ */
+
+/**
* priority levels.
*/
#define GDEV_PRIO_MAX 40
@@ -42,9 +49,9 @@
/**
* virtual device period/threshold.
*/
-#define GDEV_PERIOD_DEFAULT 100000 /*30000*/ /* microseconds */
+#define GDEV_PERIOD_DEFAULT 30000 /* microseconds */
#define GDEV_CREDIT_INACTIVE_THRESHOLD GDEV_PERIOD_DEFAULT
-#define GDEV_UPDATE_INTERVAL (GDEV_PERIOD_DEFAULT * 10)
+#define GDEV_UPDATE_INTERVAL 1000000
/**
* scheduling properties.
View
@@ -118,10 +118,16 @@ static inline void gdev_time_clear(struct gdev_time *t)
}
-/* x == y. */
+/* x == y */
static inline int gdev_time_eq(struct gdev_time *x, struct gdev_time *y)
{
- return (x->sec == y->sec) && (x->usec && y->usec);
+ return (x->sec == y->sec) && (x->usec == y->usec);
+}
+
+/* p == 0 */
+static inline int gdev_time_eqz(struct gdev_time *p)
+{
+ return (p->sec == 0) && (p->usec == 0);
}
/* x > y */
@@ -137,6 +143,12 @@ static inline int gdev_time_gt(struct gdev_time *x, struct gdev_time *y)
return (x->sec == y->sec) ? (x->usec > y->usec) : (x->sec > y->sec);
}
+/* p > 0 */
+static inline int gdev_time_gtz(struct gdev_time *p)
+{
+ return (!p->neg) && ((p->sec > 0) || (p->usec > 0));
+}
+
/* x >= y */
static inline int gdev_time_ge(struct gdev_time *x, struct gdev_time *y)
{
@@ -146,6 +158,12 @@ static inline int gdev_time_ge(struct gdev_time *x, struct gdev_time *y)
return gdev_time_gt(x, y);
}
+/* p >= 0 */
+static inline int gdev_time_gez(struct gdev_time *p)
+{
+ return gdev_time_gtz(p) || gdev_time_eqz(p);
+}
+
/* x < y */
static inline int gdev_time_lt(struct gdev_time *x, struct gdev_time *y)
{
@@ -159,6 +177,12 @@ static inline int gdev_time_lt(struct gdev_time *x, struct gdev_time *y)
return (x->sec == y->sec) ? (x->usec < y->usec) : (x->sec < y->sec);
}
+/* p < 0 */
+static inline int gdev_time_ltz(struct gdev_time *p)
+{
+ return p->neg;
+}
+
/* x <= y */
static inline int gdev_time_le(struct gdev_time *x, struct gdev_time *y)
{
@@ -168,6 +192,12 @@ static inline int gdev_time_le(struct gdev_time *x, struct gdev_time *y)
return gdev_time_lt(x, y);
}
+/* p <= 0 */
+static inline int gdev_time_lez(struct gdev_time *p)
+{
+ return gdev_time_ltz(p) || gdev_time_eqz(p);
+}
+
/* ret = x + y (x and y must be positive) */
static inline void __gdev_time_add_pos(struct gdev_time *ret, struct gdev_time *x, struct gdev_time *y)
{
Oops, something went wrong.

0 comments on commit 30bc41b

Please sign in to comment.