Permalink
Browse files

gdev: made QUERY_CHIPSET and QUERY_DEVICE_MEM_SIZE and QUERY_DMA_MEM_…

…SIZE be common queries but not nvidia specific ones

cuda: fixed query functions accordingly
gdev: added gdev_init.{c,h}, and moved gdev initialization functions to this file
gdev: added initial implementation of the Gdev scheduler (just a kernel thread)
gdev: added /proc filesystem functions
gdev: added initial support for virtual devices
  • Loading branch information...
Shinpei Kato
Shinpei Kato committed Jan 5, 2012
1 parent 71df14d commit 3ddab5efe9c3b7745609a5efdd740df0505e3686
View
@@ -25,6 +25,7 @@
#include "gdev_conf.h"
#include "gdev_mm.h"
#include "gdev_proto.h"
+#include "gdev_sched.h"
#define __max(x, y) (x) > (y) ? (x) : (y)
#define __min(x, y) (x) < (y) ? (x) : (y)
@@ -569,7 +570,7 @@ struct gdev_handle *gopen(int minor)
goto fail_vas;
/* create a new GPU context object. */
- ctx = gdev_ctx_new(gdev, vas, h);
+ ctx = gdev_ctx_new(gdev, vas);
if (!ctx)
goto fail_ctx;
@@ -587,21 +588,21 @@ struct gdev_handle *gopen(int minor)
/* insert the created VAS object to the device VAS list. */
gdev_vas_list_add(vas);
- GDEV_PRINT("Opened gdev%d.\n", minor);
+ GDEV_PRINT("Opened gdev%d\n", minor);
return h;
fail_dma:
- GDEV_PRINT("Failed to allocate static DMA buffer object.\n");
+ GDEV_PRINT("Failed to allocate static DMA buffer object\n");
gdev_ctx_free(ctx);
fail_ctx:
- GDEV_PRINT("Failed to create a context object.\n");
+ GDEV_PRINT("Failed to create a context object\n");
gdev_vas_free(vas);
fail_vas:
- GDEV_PRINT("Failed to create a virtual address space object.\n");
+ GDEV_PRINT("Failed to create a virtual address space object\n");
gdev_dev_close(gdev);
fail_open:
- GDEV_PRINT("Failed to open gdev%d.\n", minor);
+ GDEV_PRINT("Failed to open gdev%d\n", minor);
return NULL;
}
@@ -632,7 +633,7 @@ int gclose(struct gdev_handle *h)
gdev_vas_free(h->vas);
gdev_dev_close(h->gdev);
- GDEV_PRINT("Closed gdev%d.\n", h->dev_id);
+ GDEV_PRINT("Closed gdev%d\n", h->dev_id);
FREE(h);
@@ -645,19 +646,26 @@ int gclose(struct gdev_handle *h)
*/
uint64_t gmalloc(struct gdev_handle *h, uint64_t size)
{
+ struct gdev_device *gdev = h->gdev;
gdev_vas_t *vas = h->vas;
gdev_mem_t *mem;
- if (!(mem = gdev_mem_alloc(vas, size, GDEV_MEM_DEVICE))) {
+ gdev->mem_used += size;
+
+ if (gdev->mem_used > gdev->mem_size) {
/* a second chance with shared memory (only for device memory). */
if (!(mem = gdev_shmem_request(vas, NULL, size)))
goto fail;
}
+ else if (!(mem = gdev_mem_alloc(vas, size, GDEV_MEM_DEVICE)))
+ goto fail;
+
gdev_mem_list_add(mem, GDEV_MEM_DEVICE);
return GDEV_MEM_ADDR(mem);
fail:
+ gdev->mem_used -= size;
return 0;
}
@@ -667,6 +675,7 @@ uint64_t gmalloc(struct gdev_handle *h, uint64_t size)
*/
uint64_t gfree(struct gdev_handle *h, uint64_t addr)
{
+ struct gdev_device *gdev = h->gdev;
gdev_vas_t *vas = h->vas;
gdev_mem_t *mem;
uint64_t size;
@@ -677,6 +686,8 @@ uint64_t gfree(struct gdev_handle *h, uint64_t addr)
gdev_mem_list_del(mem);
gdev_mem_free(mem);
+ gdev->mem_used -= size;
+
return size;
fail:
@@ -689,16 +700,22 @@ uint64_t gfree(struct gdev_handle *h, uint64_t addr)
*/
void *gmalloc_dma(struct gdev_handle *h, uint64_t size)
{
+ struct gdev_device *gdev = h->gdev;
gdev_vas_t *vas = h->vas;
gdev_mem_t *mem;
- if (!(mem = gdev_mem_alloc(vas, size, GDEV_MEM_DMA)))
+ gdev->dma_mem_used += size;
+
+ if (gdev->dma_mem_used > gdev->dma_mem_size)
+ goto fail;
+ else if (!(mem = gdev_mem_alloc(vas, size, GDEV_MEM_DMA)))
goto fail;
gdev_mem_list_add(mem, GDEV_MEM_DMA);
return GDEV_MEM_BUF(mem);
fail:
+ gdev->dma_mem_used -= size;
return 0;
}
@@ -708,6 +725,7 @@ void *gmalloc_dma(struct gdev_handle *h, uint64_t size)
*/
uint64_t gfree_dma(struct gdev_handle *h, void *buf)
{
+ struct gdev_device *gdev = h->gdev;
gdev_vas_t *vas = h->vas;
gdev_mem_t *mem;
uint64_t size;
@@ -718,6 +736,8 @@ uint64_t gfree_dma(struct gdev_handle *h, void *buf)
gdev_mem_list_del(mem);
gdev_mem_free(mem);
+ gdev->dma_mem_used -= size;
+
return size;
fail:
@@ -847,6 +867,8 @@ int glaunch(struct gdev_handle *h, struct gdev_kernel *kernel, uint32_t *id)
gdev_vas_t *vas = h->vas;
gdev_ctx_t *ctx = h->ctx;
+ //gdev_schedule_launch(ctx);
+
gdev_shmem_lock_all(vas);
gdev_shmem_reload_all(ctx, vas); /* this reloads data only if necessary */
*id = gdev_launch(ctx, kernel);
View
@@ -73,4 +73,11 @@ int gtune(Ghandle h, uint32_t type, uint32_t value);
#define GDEV_TUNE_MEMCPY_PIPELINE_COUNT 1
#define GDEV_TUNE_MEMCPY_CHUNK_SIZE 2
+/**
+ * common queries:
+ */
+#define GDEV_QUERY_DEVICE_MEM_SIZE 1
+#define GDEV_QUERY_DMA_MEM_SIZE 2
+#define GDEV_QUERY_CHIPSET 3
+
#endif
View
@@ -29,7 +29,9 @@
// #include "gdev_amd.h"
// #include "gdev_intel.h"
-#define GDEV_DEVICE_MAX_COUNT 32
+#define GDEV_VDEVICE_COUNT 4 /* # of virtual devices */
+
+#define GDEV_CONTEXT_MAX_COUNT 128 /* # of GPU contexts */
#define GDEV_PIPELINE_MAX_COUNT 4
#define GDEV_PIPELINE_MIN_COUNT 1
View
@@ -0,0 +1,107 @@
+/*
+ * Copyright 2011 Shinpei Kato
+ *
+ * University of California, Santa Cruz
+ * Systems Research Lab.
+ *
+ * All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * VA LINUX SYSTEMS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
+ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#include "gdev_init.h"
+
+/* initialize the physical device information. */
+int gdev_init_device(struct gdev_device *gdev, int minor, void *priv)
+{
+ gdev->id = minor;
+ gdev->users = 0;
+ gdev->mem_size = 0;
+ gdev->mem_used = 0;
+ gdev->dma_mem_size = 0;
+ gdev->dma_mem_used = 0;
+ gdev->proc_util = 100; /* 100% */
+ gdev->mem_util = 100; /* 100% */
+ gdev->swap = NULL;
+ gdev->sched_thread = NULL;
+ gdev->parent = NULL;
+ gdev->priv = priv; /* this must be set before calls to gdev_query(). */
+ gdev_list_init(&gdev->vas_list, NULL); /* VAS list. */
+ LOCK_INIT(&gdev->vas_lock);
+ MUTEX_INIT(&gdev->shmem_mutex);
+
+ /* architecture-dependent chipset.
+ this call must be prior to the following. */
+ gdev_query(gdev, GDEV_QUERY_CHIPSET, (uint64_t*) &gdev->chipset);
+
+ /* device memory size available for users. */
+ gdev_query(gdev, GDEV_QUERY_DEVICE_MEM_SIZE, &gdev->mem_size);
+ /* FIXME: substract the amount of memory used not for users' data but
+ this shouldn't be hardcoded. */
+ gdev->mem_size -= 0xc010000;
+
+ /* host DMA memory size available for users. */
+ gdev_query(gdev, GDEV_QUERY_DMA_MEM_SIZE, &gdev->dma_mem_size);
+
+ /* set up the compute engine. */
+ gdev_compute_setup(gdev);
+
+ GDEV_PRINT("Device %d: memory size (device 0x%llx, host 0x%llx)\n",
+ gdev->id, gdev->mem_size, gdev->dma_mem_size);
+
+ return 0;
+}
+
+/* finalize the physical device. */
+void gdev_exit_device(struct gdev_device *gdev)
+{
+}
+
+/* initialize the virtual device information. */
+int gdev_init_vdevice
+(struct gdev_device *gdev, int id, uint32_t proc_util, uint32_t mem_util,
+ struct gdev_device *phys)
+{
+ gdev->id = id;
+ gdev->users = 0;
+ gdev->proc_util = proc_util;
+ gdev->mem_util = mem_util;
+ gdev->swap = NULL;
+ gdev->sched_thread = NULL;
+ gdev->parent = phys;
+ gdev->priv = phys->priv;
+ gdev->compute = phys->compute;
+ gdev->mem_size = phys->mem_size * mem_util / 100;
+ gdev->dma_mem_size = phys->dma_mem_size * mem_util / 100;
+ gdev->chipset = phys->chipset;
+ gdev_list_init(&gdev->vas_list, NULL); /* VAS list. */
+ LOCK_INIT(&gdev->vas_lock);
+ MUTEX_INIT(&gdev->shmem_mutex);
+
+ GDEV_PRINT("Virtual device %d: memory size (device 0x%llx, host 0x%llx)\n",
+ gdev->id, gdev->mem_size, gdev->dma_mem_size);
+
+ return 0;
+}
+
+/* finalize the virtual device. */
+void gdev_exit_vdevice(struct gdev_device *gdev)
+{
+}
View
@@ -0,0 +1,40 @@
+/*
+ * Copyright 2011 Shinpei Kato
+ *
+ * University of California, Santa Cruz
+ * Systems Research Lab.
+ *
+ * All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * VA LINUX SYSTEMS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
+ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#ifndef __GDEV_INIT_H__
+#define __GDEV_INIT_H__
+
+#include "gdev_proto.h"
+
+int gdev_init_device(struct gdev_device*, int, void*);
+void gdev_exit_device(struct gdev_device*);
+int gdev_init_vdevice(struct gdev_device*, int, uint32_t, uint32_t, struct gdev_device *);
+void gdev_exit_vdevice(struct gdev_device*);
+
+
+#endif
Oops, something went wrong.

0 comments on commit 3ddab5e

Please sign in to comment.