Permalink
Browse files

gdev: improved and fixed the Band scheduler!!!!!

  • Loading branch information...
1 parent 9e10e89 commit a486bdf405850c2b15209e38df0178643d0697d1 Shinpei Kato committed Jan 11, 2012
Showing with 47 additions and 13 deletions.
  1. +14 −3 common/gdev_nvidia_shm.c
  2. +1 −0 common/gdev_sched.c
  3. +26 −4 common/gdev_vsched_band.c
  4. +6 −6 driver/gdev/gdev_drv.c
View
@@ -29,7 +29,7 @@
#include "gdev_device.h"
#include "gdev_sched.h"
-#define GDEV_SHM_SEGMENT_COUNT 128 /* hardcoded */
+#define GDEV_SHM_SEGMENT_COUNT 512 /* hardcoded */
static struct gdev_mem *gdev_shm_owners[GDEV_SHM_SEGMENT_COUNT] = {
[0 ... GDEV_SHM_SEGMENT_COUNT - 1] = NULL
};
@@ -123,25 +123,36 @@ int gdev_shm_create(struct gdev_device *gdev, struct gdev_vas *vas, int key, uin
if (id < 0) {
/* @size could be resized (aligned by page size) */
- if (!(mem = gdev_raw_mem_alloc(vas, &addr, &size, &map)))
+ if (!(mem = gdev_raw_mem_alloc(vas, &addr, &size, &map))) {
+ GDEV_PRINT("Failed to allocate memory\n");
goto fail_mem_alloc;
+ }
gdev_nvidia_mem_init(mem, vas, addr, size, map, GDEV_MEM_DEVICE);
/* register the new shared memory segment. */
for (i = 0; i < GDEV_SHM_SEGMENT_COUNT; i++) {
if (!gdev_shm_owners[i]) {
gdev_shm_owners[i] = mem;
id = i;
- if (!(shm = MALLOC(sizeof(*shm))))
+ if (!(shm = MALLOC(sizeof(*shm)))) {
+ GDEV_PRINT("Failed to allocate heap\n");
goto fail_shm_malloc;
+ }
__gdev_shm_init(mem, shm);
gdev_list_add(&shm->list_entry, &gdev->shm_list);
shm->key = key;
shm->id = id;
+ if (id < 0) {
+ GDEV_PRINT("Allocated new shared memory segment %d\n", id);
+ }
break;
}
}
}
+ if (id < 0) {
+ GDEV_PRINT("No space in shared memory segments\n");
+ }
+
return id;
fail_shm_malloc:
View
@@ -286,6 +286,7 @@ void gdev_select_next_compute(struct gdev_device *gdev)
if (gdev_sched_wakeup(se->task) < 0) {
GDEV_PRINT("Failed to wake up context %d\n", se->ctx->cid);
+ GDEV_PRINT("Perhaps context %d is already up\n", se->ctx->cid);
}
}
else
View
@@ -26,7 +26,9 @@
* OTHER DEALINGS IN THE SOFTWARE.
*/
-static void __gdev_vsched_band_yield_chance(struct gdev_device *gdev)
+#define GDEV_VSCHED_BAND_SELECT_CHANCES 1
+
+static void __gdev_vsched_band_yield_chance(void)
{
struct gdev_time time_wait, time_now;
gdev_time_stamp(&time_now);
@@ -47,8 +49,9 @@ static void gdev_vsched_band_schedule_compute(struct gdev_sched_entity *se)
return;
resched:
- if (gdev_time_lez(&gdev->credit_com) && gdev->com_bw_used > gdev->com_bw)
- __gdev_vsched_band_yield_chance(gdev);
+ if (gdev_time_lez(&gdev->credit_com) && gdev->com_bw_used > gdev->com_bw) {
+ __gdev_vsched_band_yield_chance();
+ }
gdev_lock(&phys->sched_com_lock);
@@ -75,10 +78,12 @@ static struct gdev_device *gdev_vsched_band_select_next_compute(struct gdev_devi
{
struct gdev_device *phys = gdev->parent;
struct gdev_device *next;
+ int chances = GDEV_VSCHED_BAND_SELECT_CHANCES;
if (!phys)
return gdev;
+retry:
gdev_lock(&phys->sched_com_lock);
/* if the credit is exhausted, reinsert the device. */
@@ -99,6 +104,14 @@ static struct gdev_device *gdev_vsched_band_select_next_compute(struct gdev_devi
device_switched:
phys->current_com = (void*)next; /* could be null */
gdev_unlock(&phys->sched_com_lock);
+
+ if (next && next != gdev && next->com_bw_used > next->com_bw) {
+ phys->current_com = NULL;
+ __gdev_vsched_band_yield_chance();
+ chances--;
+ if (chances)
+ goto retry;
+ }
return next;
}
@@ -129,7 +142,7 @@ static void gdev_vsched_band_schedule_memory(struct gdev_sched_entity *se)
resched:
if (gdev_time_lez(&gdev->credit_mem) && gdev->mem_bw_used > gdev->mem_bw)
- __gdev_vsched_band_yield_chance(gdev);
+ __gdev_vsched_band_yield_chance();
gdev_lock(&phys->sched_mem_lock);
if (phys->current_mem && phys->current_mem != gdev) {
@@ -155,10 +168,12 @@ static struct gdev_device *gdev_vsched_band_select_next_memory(struct gdev_devic
{
struct gdev_device *phys = gdev->parent;
struct gdev_device *next;
+ int chances = GDEV_VSCHED_BAND_SELECT_CHANCES;
if (!phys)
return gdev;
+retry:
gdev_lock(&phys->sched_mem_lock);
/* if the credit is exhausted, reinsert the device. */
@@ -180,6 +195,13 @@ static struct gdev_device *gdev_vsched_band_select_next_memory(struct gdev_devic
phys->current_mem = (void*)next; /* could be null */
gdev_unlock(&phys->sched_mem_lock);
+ if (next && next != gdev && next->mem_bw_used > next->mem_bw) {
+ __gdev_vsched_band_yield_chance();
+ chances--;
+ if (chances)
+ goto retry;
+ }
+
return next;
}
View
@@ -146,10 +146,10 @@ static int __gdev_credit_com_thread(void *__data)
gdev_lock(&gdev->sched_com_lock);
gdev_time_stamp(&now);
gdev_time_sub(&elapse, &now, &last);
+ gdev->com_bw_used = gdev->com_time * 100 / gdev_time_to_us(&elapse);
+ if (gdev->com_bw_used > 100)
+ gdev->com_bw_used = 100;
if (gdev_time_ge(&elapse, &interval)) {
- gdev->com_bw_used = gdev->com_time * 100 / gdev_time_to_us(&elapse);
- if (gdev->com_bw_used > 100)
- gdev->com_bw_used = 100;
gdev->com_time = 0;
gdev_time_stamp(&last);
}
@@ -191,10 +191,10 @@ static int __gdev_credit_mem_thread(void *__data)
gdev_lock(&gdev->sched_mem_lock);
gdev_time_stamp(&now);
gdev_time_sub(&elapse, &now, &last);
+ gdev->mem_bw_used = gdev->mem_time * 100 / gdev_time_to_us(&elapse);
+ if (gdev->mem_bw_used > 100)
+ gdev->mem_bw_used = 100;
if (gdev_time_ge(&elapse, &interval)) {
- gdev->mem_bw_used = gdev->mem_time * 100 / gdev_time_to_us(&elapse);
- if (gdev->mem_bw_used > 100)
- gdev->mem_bw_used = 100;
gdev->mem_time = 0;
gdev_time_stamp(&last);
}

0 comments on commit a486bdf

Please sign in to comment.