Re: [Nouveau] [Mesa-dev] [PATCH] nvc0: fix geometry program revalidation of clipping params

2015-07-13 Thread Samuel Pitoiset
What piglit test does this fix?

On Sat, Jul 11, 2015 at 7:13 PM, Ilia Mirkin  wrote:

> Signed-off-by: Ilia Mirkin 
> Cc: mesa-sta...@lists.freedesktop.org
> ---
>
> Even though in practice a geometry program will never be using UCP's,
> we still were revalidating (aka recompiling) the program when more
> clip planes became enabled (which also are used for regular clip
> distances).
>
> This seems like it should have led to massive fail, but I guess you
> don't change the number of clip planes when using geometry shaders.
> But I'm going to put this through a full piglit run just in case
> there's something I'm missing.
>
>  src/gallium/drivers/nouveau/nvc0/nvc0_state_validate.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/src/gallium/drivers/nouveau/nvc0/nvc0_state_validate.c
> b/src/gallium/drivers/nouveau/nvc0/nvc0_state_validate.c
> index 785e52e..11f2b10 100644
> --- a/src/gallium/drivers/nouveau/nvc0/nvc0_state_validate.c
> +++ b/src/gallium/drivers/nouveau/nvc0/nvc0_state_validate.c
> @@ -339,7 +339,7 @@ nvc0_check_program_ucps(struct nvc0_context *nvc0,
>nvc0_vertprog_validate(nvc0);
> else
> if (likely(vp == nvc0->gmtyprog))
> -  nvc0_vertprog_validate(nvc0);
> +  nvc0_gmtyprog_validate(nvc0);
> else
>nvc0_tevlprog_validate(nvc0);
>  }
> --
> 2.3.6
>
> ___
> mesa-dev mailing list
> mesa-...@lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/mesa-dev
>



-- 
Best regards,
Samuel Pitoiset.
___
Nouveau mailing list
Nouveau@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/nouveau


Re: [Nouveau] [RFC PATCH 6/8] nv50: add support for compute/graphics global performance counters

2015-06-28 Thread Samuel Pitoiset



On 06/26/2015 01:09 AM, Ilia Mirkin wrote:

What's with the \%'s everywhere?


Maybe "percent" will be better ?



On Mon, Jun 22, 2015 at 4:53 PM, Samuel Pitoiset
 wrote:

This commit adds support for both compute and graphics global
performance counters which have been reverse engineered with
CUPTI (Linux) and PerfKit (Windows).

Currently, only one query type can be monitored at the same time because
the Gallium's HUD doesn't fit pretty well. This will be improved later.

Signed-off-by: Samuel Pitoiset 
---
  src/gallium/drivers/nouveau/nv50/nv50_query.c  | 1057 +++-
  src/gallium/drivers/nouveau/nv50/nv50_screen.h |   35 +
  2 files changed, 1087 insertions(+), 5 deletions(-)

diff --git a/src/gallium/drivers/nouveau/nv50/nv50_query.c 
b/src/gallium/drivers/nouveau/nv50/nv50_query.c
index 1162110..b9d2914 100644
--- a/src/gallium/drivers/nouveau/nv50/nv50_query.c
+++ b/src/gallium/drivers/nouveau/nv50/nv50_query.c
@@ -27,6 +27,8 @@
  #include "nv50/nv50_context.h"
  #include "nv_object.xml.h"

+#include "nouveau_perfmon.h"
+
  #define NV50_QUERY_STATE_READY   0
  #define NV50_QUERY_STATE_ACTIVE  1
  #define NV50_QUERY_STATE_ENDED   2
@@ -51,10 +53,25 @@ struct nv50_query {
 boolean is64bit;
 struct nouveau_mm_allocation *mm;
 struct nouveau_fence *fence;
+   struct nouveau_object *perfdom;
  };

  #define NV50_QUERY_ALLOC_SPACE 256

+#ifdef DEBUG
+static void nv50_hw_pm_dump_perfdom(struct nvif_perfdom_v0 *args);
+#endif
+
+static boolean
+nv50_hw_pm_query_create(struct nv50_context *, struct nv50_query *);
+static void
+nv50_hw_pm_query_destroy(struct nv50_context *, struct nv50_query *);
+static boolean
+nv50_hw_pm_query_begin(struct nv50_context *, struct nv50_query *);
+static void nv50_hw_pm_query_end(struct nv50_context *, struct nv50_query *);
+static boolean nv50_hw_pm_query_result(struct nv50_context *,
+struct nv50_query *, boolean, void *);
+
  static INLINE struct nv50_query *
  nv50_query(struct pipe_query *pipe)
  {
@@ -96,12 +113,18 @@ nv50_query_allocate(struct nv50_context *nv50, struct 
nv50_query *q, int size)
  static void
  nv50_query_destroy(struct pipe_context *pipe, struct pipe_query *pq)
  {
+   struct nv50_context *nv50 = nv50_context(pipe);
+   struct nv50_query *q = nv50_query(pq);
+
 if (!pq)
return;

-   nv50_query_allocate(nv50_context(pipe), nv50_query(pq), 0);
-   nouveau_fence_ref(NULL, &nv50_query(pq)->fence);
-   FREE(nv50_query(pq));
+   if ((q->type >= NV50_HW_PM_QUERY(0) && q->type <= NV50_HW_PM_QUERY_LAST))
+  nv50_hw_pm_query_destroy(nv50, q);
+
+   nv50_query_allocate(nv50, q, 0);
+   nouveau_fence_ref(NULL, &q->fence);
+   FREE(q);
  }

  static struct pipe_query *
@@ -130,6 +153,11 @@ nv50_query_create(struct pipe_context *pipe, unsigned 
type, unsigned index)
q->data -= 32 / sizeof(*q->data); /* we advance before query_begin ! */
 }

+   if ((q->type >= NV50_HW_PM_QUERY(0) && q->type <= NV50_HW_PM_QUERY_LAST)) {
+  if (!nv50_hw_pm_query_create(nv50, q))
+ return NULL;
+   }
+
 return (struct pipe_query *)q;
  }

@@ -154,6 +182,7 @@ nv50_query_begin(struct pipe_context *pipe, struct 
pipe_query *pq)
 struct nv50_context *nv50 = nv50_context(pipe);
 struct nouveau_pushbuf *push = nv50->base.pushbuf;
 struct nv50_query *q = nv50_query(pq);
+   boolean ret = TRUE;

 if (!pq)
return FALSE;
@@ -211,10 +240,13 @@ nv50_query_begin(struct pipe_context *pipe, struct 
pipe_query *pq)
nv50_query_get(push, q, 0x10, 0x5002);
break;
 default:
+  if ((q->type >= NV50_HW_PM_QUERY(0) && q->type <= 
NV50_HW_PM_QUERY_LAST)) {
+ ret = nv50_hw_pm_query_begin(nv50, q);
+  }
break;
 }
 q->state = NV50_QUERY_STATE_ACTIVE;
-   return true;
+   return ret;
  }

  static void
@@ -274,7 +306,9 @@ nv50_query_end(struct pipe_context *pipe, struct pipe_query 
*pq)
q->state = NV50_QUERY_STATE_READY;
break;
 default:
-  assert(0);
+  if ((q->type >= NV50_HW_PM_QUERY(0) && q->type <= 
NV50_HW_PM_QUERY_LAST)) {
+ nv50_hw_pm_query_end(nv50, q);
+  }
break;
 }

@@ -309,6 +343,10 @@ nv50_query_result(struct pipe_context *pipe, struct 
pipe_query *pq,
 if (!pq)
return FALSE;

+   if ((q->type >= NV50_HW_PM_QUERY(0) && q->type <= NV50_HW_PM_QUERY_LAST)) {
+  return nv50_hw_pm_query_result(nv50, q, wait, result);
+   }
+
 if (q->state != NV50_QUERY_STATE_READY)
nv50_query_update(q);

@@ -488,6 +526,1015 @@ nva0_so_target_save_offset(struct pipe_context *pipe,
 nv50_query_end(pipe, targ->pq);
  }

+/* === HARDWARE GLOBAL PERFORMANCE COUNTERS for NV50 === */
+
+struct nv50_hw_pm_source_cfg
+{
+   const char *name;
+   uint64_t

Re: [Nouveau] [RFC PATCH 4/8] nv50: configure the ring buffer for reading back PM counters

2015-06-28 Thread Samuel Pitoiset



On 06/26/2015 01:04 AM, Ilia Mirkin wrote:

Yeah, this whole thing has to be guarded by a drm version check,
otherwise it'll end up with errors in dmesg I assume. Perhaps only
allocate screen->query when the drm version matches, and gate things
on that for the rest of the code?


Yes, this sounds good to me.



On Mon, Jun 22, 2015 at 4:53 PM, Samuel Pitoiset
 wrote:

To write data at the right offset, the kernel has to know some
parameters of this ring buffer, like the number of domains and the
maximum number of queries.

Signed-off-by: Samuel Pitoiset 
---
  src/gallium/drivers/nouveau/nv50/nv50_screen.c | 7 +++
  1 file changed, 7 insertions(+)

diff --git a/src/gallium/drivers/nouveau/nv50/nv50_screen.c 
b/src/gallium/drivers/nouveau/nv50/nv50_screen.c
index 3a99cc8..53817c0 100644
--- a/src/gallium/drivers/nouveau/nv50/nv50_screen.c
+++ b/src/gallium/drivers/nouveau/nv50/nv50_screen.c
@@ -441,6 +441,13 @@ nv50_screen_init_hwctx(struct nv50_screen *screen)

 BEGIN_NV04(push, SUBC_SW(NV01_SUBCHAN_OBJECT), 1);
 PUSH_DATA (push, screen->sw->handle);
+   BEGIN_NV04(push, SUBC_SW(0x0190), 1);
+   PUSH_DATA (push, screen->query->handle);
+   // XXX: Maybe add a check for DRM version here ?
+   BEGIN_NV04(push, SUBC_SW(0x0600), 1);
+   PUSH_DATA (push, NV50_HW_PM_RING_BUFFER_MAX_QUERIES);
+   BEGIN_NV04(push, SUBC_SW(0x0604), 1);
+   PUSH_DATA (push, NV50_HW_PM_RING_BUFFER_NUM_DOMAINS);

FYI you can do BEGIN_NV04(..., 2), since they're sequential.


I'm going to make the change.




 BEGIN_NV04(push, NV50_3D(COND_MODE), 1);
 PUSH_DATA (push, NV50_3D_COND_MODE_ALWAYS);
--
2.4.4

___
Nouveau mailing list
Nouveau@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/nouveau


___
Nouveau mailing list
Nouveau@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/nouveau


Re: [Nouveau] [RFC PATCH 3/8] nv50: allocate and map a notifier buffer object for PM

2015-06-28 Thread Samuel Pitoiset



On 06/26/2015 01:02 AM, Ilia Mirkin wrote:

On Mon, Jun 22, 2015 at 4:53 PM, Samuel Pitoiset
 wrote:

This notifier buffer object will be used to read back global performance
counters results written by the kernel.

For each domain, we will store the handle of the perfdom object, an
array of 4 counters and the number of cycles. Like the Gallium's HUD,
we keep a list of busy queries in a ring in order to prevent stalls
when reading queries.

Signed-off-by: Samuel Pitoiset 
---
  src/gallium/drivers/nouveau/nv50/nv50_screen.c | 29 ++
  src/gallium/drivers/nouveau/nv50/nv50_screen.h |  6 ++
  2 files changed, 35 insertions(+)

diff --git a/src/gallium/drivers/nouveau/nv50/nv50_screen.c 
b/src/gallium/drivers/nouveau/nv50/nv50_screen.c
index c985344..3a99cc8 100644
--- a/src/gallium/drivers/nouveau/nv50/nv50_screen.c
+++ b/src/gallium/drivers/nouveau/nv50/nv50_screen.c
@@ -368,6 +368,7 @@ nv50_screen_destroy(struct pipe_screen *pscreen)
 nouveau_object_del(&screen->m2mf);
 nouveau_object_del(&screen->sync);
 nouveau_object_del(&screen->sw);
+   nouveau_object_del(&screen->query);

 nouveau_screen_fini(&screen->base);

@@ -699,9 +700,11 @@ nv50_screen_create(struct nouveau_device *dev)
 struct nv50_screen *screen;
 struct pipe_screen *pscreen;
 struct nouveau_object *chan;
+   struct nv04_fifo *fifo;
 uint64_t value;
 uint32_t tesla_class;
 unsigned stack_size;
+   uint32_t length;
 int ret;

 screen = CALLOC_STRUCT(nv50_screen);
@@ -727,6 +730,7 @@ nv50_screen_create(struct nouveau_device *dev)
 screen->base.pushbuf->rsvd_kick = 5;

 chan = screen->base.channel;
+   fifo = chan->data;

 pscreen->destroy = nv50_screen_destroy;
 pscreen->context_create = nv50_create;
@@ -772,6 +776,23 @@ nv50_screen_create(struct nouveau_device *dev)
goto fail;
 }

+   /* Compute size (in bytes) of the notifier buffer object which is used
+* in order to read back global performance counters results written
+* by the kernel. For each domain, we store the handle of the perfdom
+* object, an array of 4 counters and the number of cycles. Like for
+* the Gallium's HUD, we keep a list of busy queries in a ring in order
+* to prevent stalls when reading queries. */
+   length = (1 + (NV50_HW_PM_RING_BUFFER_NUM_DOMAINS * 6) *
+  NV50_HW_PM_RING_BUFFER_MAX_QUERIES) * 4;

This calculation may become apparent to me later, but it certainly
isn't now. What's the *6? You refer to an array of 4 counters...
should that have been 6 counters? Or should this have been a 4?


This refers to the handle of the object, the array of 4 counters and the 
number of cycles.

In other words, for each domain we store: id, ctr0, ctr1, ctr2, ctr3, clk.




+
+   ret = nouveau_object_new(chan, 0xbeef0302, NOUVEAU_NOTIFIER_CLASS,
+&(struct nv04_notify){ .length = length },
+sizeof(struct nv04_notify), &screen->query);
+   if (ret) {
+   NOUVEAU_ERR("Failed to allocate notifier object for PM: %d\n", ret);
+   goto fail;
+   }
+
 ret = nouveau_object_new(chan, 0xbeef506e, 0x506e,
  NULL, 0, &screen->sw);
 if (ret) {
@@ -845,6 +866,14 @@ nv50_screen_create(struct nouveau_device *dev)
 nouveau_heap_init(&screen->gp_code_heap, 0, 1 << NV50_CODE_BO_SIZE_LOG2);
 nouveau_heap_init(&screen->fp_code_heap, 0, 1 << NV50_CODE_BO_SIZE_LOG2);

+   ret = nouveau_bo_wrap(screen->base.device, fifo->notify, 
&screen->notify_bo);
+   if (ret == 0)
+  nouveau_bo_map(screen->notify_bo, 0, screen->base.client);

ret = ...


Good catch, thanks.




+   if (ret) {
+  NOUVEAU_ERR("Failed to map notifier object for PM: %d\n", ret);
+  goto fail;
+   }
+
 nouveau_getparam(dev, NOUVEAU_GETPARAM_GRAPH_UNITS, &value);

 screen->TPs = util_bitcount(value & 0x);
diff --git a/src/gallium/drivers/nouveau/nv50/nv50_screen.h 
b/src/gallium/drivers/nouveau/nv50/nv50_screen.h
index 69fdfdb..71a5247 100644
--- a/src/gallium/drivers/nouveau/nv50/nv50_screen.h
+++ b/src/gallium/drivers/nouveau/nv50/nv50_screen.h
@@ -59,6 +59,7 @@ struct nv50_screen {
 struct nouveau_bo *txc; /* TIC (offset 0) and TSC (65536) */
 struct nouveau_bo *stack_bo;
 struct nouveau_bo *tls_bo;
+   struct nouveau_bo *notify_bo;

 unsigned TPs;
 unsigned MPsInTP;
@@ -89,6 +90,7 @@ struct nv50_screen {
 } fence;

 struct nouveau_object *sync;
+   struct nouveau_object *query;

 struct nouveau_object *tesla;
 struct nouveau_object *eng2d;
@@ -96,6 +98,10 @@ struct nv50_screen {
 struct nouveau_object *sw;
  };

+/* Parameters of the ring buffer used to read back global PM counters. */
+#define NV50_HW_PM_RING_BUFFER_NUM_DOMAINS 

Re: [Nouveau] [Mesa-dev] [RFC PATCH 5/8] nv50: prevent NULL pointer dereference with pipe_query functions

2015-06-23 Thread Samuel Pitoiset



On 06/23/2015 08:57 AM, Michel Dänzer wrote:

On 23.06.2015 06:02, Samuel Pitoiset wrote:


On 06/22/2015 10:52 PM, Ilia Mirkin wrote:

If query_create fails, why would any of these functions get called?

Because the HUD doesn't check if query_create() fails and it calls other
pipe_query functions with NULL pointer instead of a valid query object.

Could the HUD code be fixed instead?
It's definitely possible, and probably the best solution instead of 
preventing NULL pointer dereference in the underlying drivers. I'll make 
a patch.





___
Nouveau mailing list
Nouveau@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/nouveau


Re: [Nouveau] [RFC PATCH 5/8] nv50: prevent NULL pointer dereference with pipe_query functions

2015-06-22 Thread Samuel Pitoiset



On 06/22/2015 10:52 PM, Ilia Mirkin wrote:

If query_create fails, why would any of these functions get called?


Because the HUD doesn't check if query_create() fails and it calls other 
pipe_query functions with NULL pointer instead of a valid query object.




On Mon, Jun 22, 2015 at 4:53 PM, Samuel Pitoiset
 wrote:

This may happen when nv50_query_create() fails to create a new query.

Signed-off-by: Samuel Pitoiset 
---
  src/gallium/drivers/nouveau/nv50/nv50_query.c | 15 ++-
  1 file changed, 14 insertions(+), 1 deletion(-)

diff --git a/src/gallium/drivers/nouveau/nv50/nv50_query.c 
b/src/gallium/drivers/nouveau/nv50/nv50_query.c
index 55fcac8..1162110 100644
--- a/src/gallium/drivers/nouveau/nv50/nv50_query.c
+++ b/src/gallium/drivers/nouveau/nv50/nv50_query.c
@@ -96,6 +96,9 @@ nv50_query_allocate(struct nv50_context *nv50, struct 
nv50_query *q, int size)
  static void
  nv50_query_destroy(struct pipe_context *pipe, struct pipe_query *pq)
  {
+   if (!pq)
+  return;
+
 nv50_query_allocate(nv50_context(pipe), nv50_query(pq), 0);
 nouveau_fence_ref(NULL, &nv50_query(pq)->fence);
 FREE(nv50_query(pq));
@@ -152,6 +155,9 @@ nv50_query_begin(struct pipe_context *pipe, struct 
pipe_query *pq)
 struct nouveau_pushbuf *push = nv50->base.pushbuf;
 struct nv50_query *q = nv50_query(pq);

+   if (!pq)
+  return FALSE;
+
 /* For occlusion queries we have to change the storage, because a previous
  * query might set the initial render conition to FALSE even *after* we re-
  * initialized it to TRUE.
@@ -218,6 +224,9 @@ nv50_query_end(struct pipe_context *pipe, struct pipe_query 
*pq)
 struct nouveau_pushbuf *push = nv50->base.pushbuf;
 struct nv50_query *q = nv50_query(pq);

+   if (!pq)
+  return;
+
 q->state = NV50_QUERY_STATE_ENDED;

 switch (q->type) {
@@ -294,9 +303,12 @@ nv50_query_result(struct pipe_context *pipe, struct 
pipe_query *pq,
 uint64_t *res64 = (uint64_t *)result;
 uint32_t *res32 = (uint32_t *)result;
 boolean *res8 = (boolean *)result;
-   uint64_t *data64 = (uint64_t *)q->data;
+   uint64_t *data64;
 int i;

+   if (!pq)
+  return FALSE;
+
 if (q->state != NV50_QUERY_STATE_READY)
nv50_query_update(q);

@@ -314,6 +326,7 @@ nv50_query_result(struct pipe_context *pipe, struct 
pipe_query *pq,
 }
 q->state = NV50_QUERY_STATE_READY;

+   data64 = (uint64_t *)q->data;
 switch (q->type) {
 case PIPE_QUERY_GPU_FINISHED:
res8[0] = TRUE;
--
2.4.4

___
Nouveau mailing list
Nouveau@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/nouveau


___
Nouveau mailing list
Nouveau@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/nouveau


[Nouveau] [RFC PATCH 2/8] nv50: allocate a software object class

2015-06-22 Thread Samuel Pitoiset
This will allow to monitor global performance counters through the
command stream of the GPU instead of using ioctls.

Signed-off-by: Samuel Pitoiset 
---
 src/gallium/drivers/nouveau/nv50/nv50_screen.c | 11 +++
 src/gallium/drivers/nouveau/nv50/nv50_screen.h |  1 +
 src/gallium/drivers/nouveau/nv50/nv50_winsys.h |  1 +
 3 files changed, 13 insertions(+)

diff --git a/src/gallium/drivers/nouveau/nv50/nv50_screen.c 
b/src/gallium/drivers/nouveau/nv50/nv50_screen.c
index 6583a35..c985344 100644
--- a/src/gallium/drivers/nouveau/nv50/nv50_screen.c
+++ b/src/gallium/drivers/nouveau/nv50/nv50_screen.c
@@ -367,6 +367,7 @@ nv50_screen_destroy(struct pipe_screen *pscreen)
nouveau_object_del(&screen->eng2d);
nouveau_object_del(&screen->m2mf);
nouveau_object_del(&screen->sync);
+   nouveau_object_del(&screen->sw);
 
nouveau_screen_fini(&screen->base);
 
@@ -437,6 +438,9 @@ nv50_screen_init_hwctx(struct nv50_screen *screen)
BEGIN_NV04(push, SUBC_3D(NV01_SUBCHAN_OBJECT), 1);
PUSH_DATA (push, screen->tesla->handle);
 
+   BEGIN_NV04(push, SUBC_SW(NV01_SUBCHAN_OBJECT), 1);
+   PUSH_DATA (push, screen->sw->handle);
+
BEGIN_NV04(push, NV50_3D(COND_MODE), 1);
PUSH_DATA (push, NV50_3D_COND_MODE_ALWAYS);
 
@@ -768,6 +772,13 @@ nv50_screen_create(struct nouveau_device *dev)
   goto fail;
}
 
+   ret = nouveau_object_new(chan, 0xbeef506e, 0x506e,
+NULL, 0, &screen->sw);
+   if (ret) {
+  NOUVEAU_ERR("Failed to allocate SW object: %d\n", ret);
+  goto fail;
+   }
+
ret = nouveau_object_new(chan, 0xbeef5039, NV50_M2MF_CLASS,
 NULL, 0, &screen->m2mf);
if (ret) {
diff --git a/src/gallium/drivers/nouveau/nv50/nv50_screen.h 
b/src/gallium/drivers/nouveau/nv50/nv50_screen.h
index 881051b..69fdfdb 100644
--- a/src/gallium/drivers/nouveau/nv50/nv50_screen.h
+++ b/src/gallium/drivers/nouveau/nv50/nv50_screen.h
@@ -93,6 +93,7 @@ struct nv50_screen {
struct nouveau_object *tesla;
struct nouveau_object *eng2d;
struct nouveau_object *m2mf;
+   struct nouveau_object *sw;
 };
 
 static INLINE struct nv50_screen *
diff --git a/src/gallium/drivers/nouveau/nv50/nv50_winsys.h 
b/src/gallium/drivers/nouveau/nv50/nv50_winsys.h
index e8578c8..5cb33ef 100644
--- a/src/gallium/drivers/nouveau/nv50/nv50_winsys.h
+++ b/src/gallium/drivers/nouveau/nv50/nv50_winsys.h
@@ -60,6 +60,7 @@ PUSH_REFN(struct nouveau_pushbuf *push, struct nouveau_bo 
*bo, uint32_t flags)
 #define SUBC_COMPUTE(m) 6, (m)
 #define NV50_COMPUTE(n) SUBC_COMPUTE(NV50_COMPUTE_##n)
 
+#define SUBC_SW(m) 7, (m)
 
 static INLINE uint32_t
 NV50_FIFO_PKHDR(int subc, int mthd, unsigned size)
-- 
2.4.4

___
Nouveau mailing list
Nouveau@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/nouveau


[Nouveau] [RFC PATCH 1/8] nouveau: implement the nvif hardware performance counters interface

2015-06-22 Thread Samuel Pitoiset
This commit implements the base interface for hardware performance
counters that will be shared between nv50 and nvc0 drivers.

TODO: Bump libdrm version of mesa when nvif will be merged.

Signed-off-by: Samuel Pitoiset 
---
 src/gallium/drivers/nouveau/Makefile.sources  |   2 +
 src/gallium/drivers/nouveau/nouveau_perfmon.c | 302 ++
 src/gallium/drivers/nouveau/nouveau_perfmon.h |  59 +
 src/gallium/drivers/nouveau/nouveau_screen.c  |   5 +
 src/gallium/drivers/nouveau/nouveau_screen.h  |   1 +
 5 files changed, 369 insertions(+)
 create mode 100644 src/gallium/drivers/nouveau/nouveau_perfmon.c
 create mode 100644 src/gallium/drivers/nouveau/nouveau_perfmon.h

diff --git a/src/gallium/drivers/nouveau/Makefile.sources 
b/src/gallium/drivers/nouveau/Makefile.sources
index 3fae3bc..3da0bdc 100644
--- a/src/gallium/drivers/nouveau/Makefile.sources
+++ b/src/gallium/drivers/nouveau/Makefile.sources
@@ -10,6 +10,8 @@ C_SOURCES := \
nouveau_heap.h \
nouveau_mm.c \
nouveau_mm.h \
+   nouveau_perfmon.c \
+   nouveau_perfmon.h \
nouveau_screen.c \
nouveau_screen.h \
nouveau_statebuf.h \
diff --git a/src/gallium/drivers/nouveau/nouveau_perfmon.c 
b/src/gallium/drivers/nouveau/nouveau_perfmon.c
new file mode 100644
index 000..3798612
--- /dev/null
+++ b/src/gallium/drivers/nouveau/nouveau_perfmon.c
@@ -0,0 +1,302 @@
+/*
+ * Copyright 2015 Samuel Pitoiset
+ *
+ * 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 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
+ * THE AUTHORS OR COPYRIGHT HOLDERS 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 
+
+#include "util/u_memory.h"
+
+#include "nouveau_debug.h"
+#include "nouveau_winsys.h"
+#include "nouveau_perfmon.h"
+
+static int
+nouveau_perfmon_query_sources(struct nouveau_perfmon *pm,
+  struct nouveau_perfmon_dom *dom,
+  struct nouveau_perfmon_sig *sig)
+{
+   struct nvif_perfmon_query_source_v0 args = {};
+
+   args.domain = dom->id;
+   args.signal = sig->signal;
+   do {
+   uint8_t prev_iter = args.iter;
+   struct nouveau_perfmon_src *src;
+   int ret;
+
+   ret = nouveau_object_mthd(pm->object, 
NVIF_PERFMON_V0_QUERY_SOURCE,
+   &args, sizeof(args));
+   if (ret)
+   return ret;
+
+   if (prev_iter) {
+   args.iter = prev_iter;
+   ret = nouveau_object_mthd(pm->object, 
NVIF_PERFMON_V0_QUERY_SOURCE,
+   &args, 
sizeof(args));
+   if (ret)
+   return ret;
+
+   src = CALLOC_STRUCT(nouveau_perfmon_src);
+   if (!src)
+   return -ENOMEM;
+
+#if 0
+   debug_printf("id   = %d\n", args.source);
+   debug_printf("name = %s\n", args.name);
+   debug_printf("mask = %08x\n", args.mask);
+   debug_printf("\n");
+#endif
+
+  src->id = args.source;
+ strncpy(src->name, args.name, sizeof(src->name));
+   list_addtail(&src->head, &sig->sources);
+   }
+   } while (args.iter != 0xff);
+
+   return 0;
+}
+
+static int
+nouveau_perfmon_query_signals(struct nouveau_perfmon *pm,
+  struct nouveau_perfmon_dom *dom)
+{
+   struct nvif_perfmon_query_signal_v0 args = {};
+
+   args.domain = dom->id;
+   do {
+  uint16_t prev_iter = args.iter;
+  struct nouveau_perfmon_sig *sig;
+  int ret;
+
+  ret = nouveau_object_mthd(pm->object, NVIF_PERFMON_V0_QUERY_SIGNAL,
+&args, sizeof(args));
+  if (ret)
+   

[Nouveau] [RFC PATCH 5/8] nv50: prevent NULL pointer dereference with pipe_query functions

2015-06-22 Thread Samuel Pitoiset
This may happen when nv50_query_create() fails to create a new query.

Signed-off-by: Samuel Pitoiset 
---
 src/gallium/drivers/nouveau/nv50/nv50_query.c | 15 ++-
 1 file changed, 14 insertions(+), 1 deletion(-)

diff --git a/src/gallium/drivers/nouveau/nv50/nv50_query.c 
b/src/gallium/drivers/nouveau/nv50/nv50_query.c
index 55fcac8..1162110 100644
--- a/src/gallium/drivers/nouveau/nv50/nv50_query.c
+++ b/src/gallium/drivers/nouveau/nv50/nv50_query.c
@@ -96,6 +96,9 @@ nv50_query_allocate(struct nv50_context *nv50, struct 
nv50_query *q, int size)
 static void
 nv50_query_destroy(struct pipe_context *pipe, struct pipe_query *pq)
 {
+   if (!pq)
+  return;
+
nv50_query_allocate(nv50_context(pipe), nv50_query(pq), 0);
nouveau_fence_ref(NULL, &nv50_query(pq)->fence);
FREE(nv50_query(pq));
@@ -152,6 +155,9 @@ nv50_query_begin(struct pipe_context *pipe, struct 
pipe_query *pq)
struct nouveau_pushbuf *push = nv50->base.pushbuf;
struct nv50_query *q = nv50_query(pq);
 
+   if (!pq)
+  return FALSE;
+
/* For occlusion queries we have to change the storage, because a previous
 * query might set the initial render conition to FALSE even *after* we re-
 * initialized it to TRUE.
@@ -218,6 +224,9 @@ nv50_query_end(struct pipe_context *pipe, struct pipe_query 
*pq)
struct nouveau_pushbuf *push = nv50->base.pushbuf;
struct nv50_query *q = nv50_query(pq);
 
+   if (!pq)
+  return;
+
q->state = NV50_QUERY_STATE_ENDED;
 
switch (q->type) {
@@ -294,9 +303,12 @@ nv50_query_result(struct pipe_context *pipe, struct 
pipe_query *pq,
uint64_t *res64 = (uint64_t *)result;
uint32_t *res32 = (uint32_t *)result;
boolean *res8 = (boolean *)result;
-   uint64_t *data64 = (uint64_t *)q->data;
+   uint64_t *data64;
int i;
 
+   if (!pq)
+  return FALSE;
+
if (q->state != NV50_QUERY_STATE_READY)
   nv50_query_update(q);
 
@@ -314,6 +326,7 @@ nv50_query_result(struct pipe_context *pipe, struct 
pipe_query *pq,
}
q->state = NV50_QUERY_STATE_READY;
 
+   data64 = (uint64_t *)q->data;
switch (q->type) {
case PIPE_QUERY_GPU_FINISHED:
   res8[0] = TRUE;
-- 
2.4.4

___
Nouveau mailing list
Nouveau@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/nouveau


[Nouveau] [RFC PATCH 4/8] nv50: configure the ring buffer for reading back PM counters

2015-06-22 Thread Samuel Pitoiset
To write data at the right offset, the kernel has to know some
parameters of this ring buffer, like the number of domains and the
maximum number of queries.

Signed-off-by: Samuel Pitoiset 
---
 src/gallium/drivers/nouveau/nv50/nv50_screen.c | 7 +++
 1 file changed, 7 insertions(+)

diff --git a/src/gallium/drivers/nouveau/nv50/nv50_screen.c 
b/src/gallium/drivers/nouveau/nv50/nv50_screen.c
index 3a99cc8..53817c0 100644
--- a/src/gallium/drivers/nouveau/nv50/nv50_screen.c
+++ b/src/gallium/drivers/nouveau/nv50/nv50_screen.c
@@ -441,6 +441,13 @@ nv50_screen_init_hwctx(struct nv50_screen *screen)
 
BEGIN_NV04(push, SUBC_SW(NV01_SUBCHAN_OBJECT), 1);
PUSH_DATA (push, screen->sw->handle);
+   BEGIN_NV04(push, SUBC_SW(0x0190), 1);
+   PUSH_DATA (push, screen->query->handle);
+   // XXX: Maybe add a check for DRM version here ?
+   BEGIN_NV04(push, SUBC_SW(0x0600), 1);
+   PUSH_DATA (push, NV50_HW_PM_RING_BUFFER_MAX_QUERIES);
+   BEGIN_NV04(push, SUBC_SW(0x0604), 1);
+   PUSH_DATA (push, NV50_HW_PM_RING_BUFFER_NUM_DOMAINS);
 
BEGIN_NV04(push, NV50_3D(COND_MODE), 1);
PUSH_DATA (push, NV50_3D_COND_MODE_ALWAYS);
-- 
2.4.4

___
Nouveau mailing list
Nouveau@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/nouveau


[Nouveau] [RFC PATCH 0/8] nv50: expose global performance counters

2015-06-22 Thread Samuel Pitoiset
Hello there,

This series exposes NVIDIA's global performance counters for Tesla through the
Gallium's HUD and the GL_AMD_performance_monitor extension.

This adds support for 24 hardware events which have been reverse engineered
with PerfKit (Windows) and CUPTI (Linux). These hardware events will allow
developers to profile OpenGL applications.

To reduce latency and to improve accuracy, these global performance counters
are tied to the command stream of the GPU using a set of software methods
instead of ioctls. Results are then written by the kernel to a mapped notifier
buffer object that allows the userspace to read back them.

However, the libdrm branch which implements the new nvif interface exposed by
Nouveau and the software methods interface are not upstream yet. I hope this
should done in the next days.

The code of this series can be found here:
http://cgit.freedesktop.org/~hakzsam/mesa/log/?h=nouveau_perfmon

The libdrm branch can be found here:
http://cgit.freedesktop.org/~hakzsam/drm/log/?h=nouveau_perfmon

The code of the software methods interface can be found here (two last commits):
http://cgit.freedesktop.org/~hakzsam/nouveau/log/?h=nouveau_perfmon

An other series which exposes global performance counters for Fermi and Kepler
will be submitted once I have got enough reviews for this one.

Feel free to make a review.

Thanks,
Samuel.

Samuel Pitoiset (8):
  nouveau: implement the nvif hardware performance counters interface
  nv50: allocate a software object class
  nv50: allocate and map a notifier buffer object for PM
  nv50: configure the ring buffer for reading back PM counters
  nv50: prevent NULL pointer dereference with pipe_query functions
  nv50: add support for compute/graphics global performance counters
  nv50: expose global performance counters to the HUD
  nv50: enable GL_AMD_performance_monitor

 src/gallium/drivers/nouveau/Makefile.sources   |2 +
 src/gallium/drivers/nouveau/nouveau_perfmon.c  |  302 +++
 src/gallium/drivers/nouveau/nouveau_perfmon.h  |   59 ++
 src/gallium/drivers/nouveau/nouveau_screen.c   |5 +
 src/gallium/drivers/nouveau/nouveau_screen.h   |1 +
 src/gallium/drivers/nouveau/nv50/nv50_query.c  | 1148 +++-
 src/gallium/drivers/nouveau/nv50/nv50_screen.c |   49 +
 src/gallium/drivers/nouveau/nv50/nv50_screen.h |   51 ++
 src/gallium/drivers/nouveau/nv50/nv50_winsys.h |1 +
 9 files changed, 1612 insertions(+), 6 deletions(-)
 create mode 100644 src/gallium/drivers/nouveau/nouveau_perfmon.c
 create mode 100644 src/gallium/drivers/nouveau/nouveau_perfmon.h

-- 
2.4.4

___
Nouveau mailing list
Nouveau@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/nouveau


[Nouveau] [RFC PATCH 7/8] nv50: expose global performance counters to the HUD

2015-06-22 Thread Samuel Pitoiset
Signed-off-by: Samuel Pitoiset 
---
 src/gallium/drivers/nouveau/nv50/nv50_query.c  | 41 ++
 src/gallium/drivers/nouveau/nv50/nv50_screen.c |  1 +
 src/gallium/drivers/nouveau/nv50/nv50_screen.h |  3 ++
 3 files changed, 45 insertions(+)

diff --git a/src/gallium/drivers/nouveau/nv50/nv50_query.c 
b/src/gallium/drivers/nouveau/nv50/nv50_query.c
index b9d2914..062d427 100644
--- a/src/gallium/drivers/nouveau/nv50/nv50_query.c
+++ b/src/gallium/drivers/nouveau/nv50/nv50_query.c
@@ -1535,6 +1535,47 @@ nv50_hw_pm_query_result(struct nv50_context *nv50, 
struct nv50_query *q,
return TRUE;
 }
 
+int
+nv50_screen_get_driver_query_info(struct pipe_screen *pscreen,
+  unsigned id,
+  struct pipe_driver_query_info *info)
+{
+   struct nv50_screen *screen = nv50_screen(pscreen);
+   int count = 0;
+
+   // TODO: Check DRM version when nvif will be merged in libdrm!
+   if (screen->base.perfmon) {
+  nv50_identify_events(screen);
+  count += NV50_HW_PM_QUERY_COUNT;
+   }
+
+   if (!info)
+  return count;
+
+   /* Init default values. */
+   info->name = "this_is_not_the_query_you_are_looking_for";
+   info->query_type = 0xdeadd01d;
+   info->type = PIPE_DRIVER_QUERY_TYPE_UINT64;
+   info->max_value.u64 = 0;
+   info->group_id = -1;
+
+   if (id < count) {
+  if (screen->base.perfmon) {
+ const struct nv50_hw_pm_query_cfg *cfg =
+nv50_hw_pm_query_get_cfg(screen, NV50_HW_PM_QUERY(id));
+
+ info->name = cfg->event->name;
+ info->query_type = NV50_HW_PM_QUERY(id);
+ info->max_value.u64 =
+(cfg->event->display == NV50_HW_PM_EVENT_DISPLAY_RATIO) ? 100 : 0;
+ return 1;
+  }
+   }
+
+   /* User asked for info about non-existing query. */
+   return 0;
+}
+
 void
 nv50_init_query_functions(struct nv50_context *nv50)
 {
diff --git a/src/gallium/drivers/nouveau/nv50/nv50_screen.c 
b/src/gallium/drivers/nouveau/nv50/nv50_screen.c
index 53817c0..f07798e 100644
--- a/src/gallium/drivers/nouveau/nv50/nv50_screen.c
+++ b/src/gallium/drivers/nouveau/nv50/nv50_screen.c
@@ -745,6 +745,7 @@ nv50_screen_create(struct nouveau_device *dev)
pscreen->get_param = nv50_screen_get_param;
pscreen->get_shader_param = nv50_screen_get_shader_param;
pscreen->get_paramf = nv50_screen_get_paramf;
+   pscreen->get_driver_query_info = nv50_screen_get_driver_query_info;
 
nv50_screen_init_resource_functions(pscreen);
 
diff --git a/src/gallium/drivers/nouveau/nv50/nv50_screen.h 
b/src/gallium/drivers/nouveau/nv50/nv50_screen.h
index 0449659..69127c0 100644
--- a/src/gallium/drivers/nouveau/nv50/nv50_screen.h
+++ b/src/gallium/drivers/nouveau/nv50/nv50_screen.h
@@ -143,6 +143,9 @@ nv50_screen(struct pipe_screen *screen)
 #define NV50_HW_PM_QUERY_TEX_CACHE_HIT  22
 #define NV50_HW_PM_QUERY_TEX_WAITS_FOR_FB   23
 
+int nv50_screen_get_driver_query_info(struct pipe_screen *, unsigned,
+  struct pipe_driver_query_info *);
+
 boolean nv50_blitter_create(struct nv50_screen *);
 void nv50_blitter_destroy(struct nv50_screen *);
 
-- 
2.4.4

___
Nouveau mailing list
Nouveau@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/nouveau


[Nouveau] [RFC PATCH 3/8] nv50: allocate and map a notifier buffer object for PM

2015-06-22 Thread Samuel Pitoiset
This notifier buffer object will be used to read back global performance
counters results written by the kernel.

For each domain, we will store the handle of the perfdom object, an
array of 4 counters and the number of cycles. Like the Gallium's HUD,
we keep a list of busy queries in a ring in order to prevent stalls
when reading queries.

Signed-off-by: Samuel Pitoiset 
---
 src/gallium/drivers/nouveau/nv50/nv50_screen.c | 29 ++
 src/gallium/drivers/nouveau/nv50/nv50_screen.h |  6 ++
 2 files changed, 35 insertions(+)

diff --git a/src/gallium/drivers/nouveau/nv50/nv50_screen.c 
b/src/gallium/drivers/nouveau/nv50/nv50_screen.c
index c985344..3a99cc8 100644
--- a/src/gallium/drivers/nouveau/nv50/nv50_screen.c
+++ b/src/gallium/drivers/nouveau/nv50/nv50_screen.c
@@ -368,6 +368,7 @@ nv50_screen_destroy(struct pipe_screen *pscreen)
nouveau_object_del(&screen->m2mf);
nouveau_object_del(&screen->sync);
nouveau_object_del(&screen->sw);
+   nouveau_object_del(&screen->query);
 
nouveau_screen_fini(&screen->base);
 
@@ -699,9 +700,11 @@ nv50_screen_create(struct nouveau_device *dev)
struct nv50_screen *screen;
struct pipe_screen *pscreen;
struct nouveau_object *chan;
+   struct nv04_fifo *fifo;
uint64_t value;
uint32_t tesla_class;
unsigned stack_size;
+   uint32_t length;
int ret;
 
screen = CALLOC_STRUCT(nv50_screen);
@@ -727,6 +730,7 @@ nv50_screen_create(struct nouveau_device *dev)
screen->base.pushbuf->rsvd_kick = 5;
 
chan = screen->base.channel;
+   fifo = chan->data;
 
pscreen->destroy = nv50_screen_destroy;
pscreen->context_create = nv50_create;
@@ -772,6 +776,23 @@ nv50_screen_create(struct nouveau_device *dev)
   goto fail;
}
 
+   /* Compute size (in bytes) of the notifier buffer object which is used
+* in order to read back global performance counters results written
+* by the kernel. For each domain, we store the handle of the perfdom
+* object, an array of 4 counters and the number of cycles. Like for
+* the Gallium's HUD, we keep a list of busy queries in a ring in order
+* to prevent stalls when reading queries. */
+   length = (1 + (NV50_HW_PM_RING_BUFFER_NUM_DOMAINS * 6) *
+  NV50_HW_PM_RING_BUFFER_MAX_QUERIES) * 4;
+
+   ret = nouveau_object_new(chan, 0xbeef0302, NOUVEAU_NOTIFIER_CLASS,
+&(struct nv04_notify){ .length = length },
+sizeof(struct nv04_notify), &screen->query);
+   if (ret) {
+   NOUVEAU_ERR("Failed to allocate notifier object for PM: %d\n", ret);
+   goto fail;
+   }
+
ret = nouveau_object_new(chan, 0xbeef506e, 0x506e,
 NULL, 0, &screen->sw);
if (ret) {
@@ -845,6 +866,14 @@ nv50_screen_create(struct nouveau_device *dev)
nouveau_heap_init(&screen->gp_code_heap, 0, 1 << NV50_CODE_BO_SIZE_LOG2);
nouveau_heap_init(&screen->fp_code_heap, 0, 1 << NV50_CODE_BO_SIZE_LOG2);
 
+   ret = nouveau_bo_wrap(screen->base.device, fifo->notify, 
&screen->notify_bo);
+   if (ret == 0)
+  nouveau_bo_map(screen->notify_bo, 0, screen->base.client);
+   if (ret) {
+  NOUVEAU_ERR("Failed to map notifier object for PM: %d\n", ret);
+  goto fail;
+   }
+
nouveau_getparam(dev, NOUVEAU_GETPARAM_GRAPH_UNITS, &value);
 
screen->TPs = util_bitcount(value & 0x);
diff --git a/src/gallium/drivers/nouveau/nv50/nv50_screen.h 
b/src/gallium/drivers/nouveau/nv50/nv50_screen.h
index 69fdfdb..71a5247 100644
--- a/src/gallium/drivers/nouveau/nv50/nv50_screen.h
+++ b/src/gallium/drivers/nouveau/nv50/nv50_screen.h
@@ -59,6 +59,7 @@ struct nv50_screen {
struct nouveau_bo *txc; /* TIC (offset 0) and TSC (65536) */
struct nouveau_bo *stack_bo;
struct nouveau_bo *tls_bo;
+   struct nouveau_bo *notify_bo;
 
unsigned TPs;
unsigned MPsInTP;
@@ -89,6 +90,7 @@ struct nv50_screen {
} fence;
 
struct nouveau_object *sync;
+   struct nouveau_object *query;
 
struct nouveau_object *tesla;
struct nouveau_object *eng2d;
@@ -96,6 +98,10 @@ struct nv50_screen {
struct nouveau_object *sw;
 };
 
+/* Parameters of the ring buffer used to read back global PM counters. */
+#define NV50_HW_PM_RING_BUFFER_NUM_DOMAINS 8
+#define NV50_HW_PM_RING_BUFFER_MAX_QUERIES 9 /* HUD_NUM_QUERIES + 1 */
+
 static INLINE struct nv50_screen *
 nv50_screen(struct pipe_screen *screen)
 {
-- 
2.4.4

___
Nouveau mailing list
Nouveau@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/nouveau


[Nouveau] [RFC PATCH 8/8] nv50: enable GL_AMD_performance_monitor

2015-06-22 Thread Samuel Pitoiset
This exposes a group of global performance counters that enables
GL_AMD_performance_monitor. All piglit tests are okay.

Signed-off-by: Samuel Pitoiset 
---
 src/gallium/drivers/nouveau/nv50/nv50_query.c  | 35 ++
 src/gallium/drivers/nouveau/nv50/nv50_screen.c |  1 +
 src/gallium/drivers/nouveau/nv50/nv50_screen.h |  6 +
 3 files changed, 42 insertions(+)

diff --git a/src/gallium/drivers/nouveau/nv50/nv50_query.c 
b/src/gallium/drivers/nouveau/nv50/nv50_query.c
index 062d427..6638e82 100644
--- a/src/gallium/drivers/nouveau/nv50/nv50_query.c
+++ b/src/gallium/drivers/nouveau/nv50/nv50_query.c
@@ -1566,6 +1566,7 @@ nv50_screen_get_driver_query_info(struct pipe_screen 
*pscreen,
 
  info->name = cfg->event->name;
  info->query_type = NV50_HW_PM_QUERY(id);
+ info->group_id = NV50_HW_PM_QUERY_GROUP;
  info->max_value.u64 =
 (cfg->event->display == NV50_HW_PM_EVENT_DISPLAY_RATIO) ? 100 : 0;
  return 1;
@@ -1576,6 +1577,40 @@ nv50_screen_get_driver_query_info(struct pipe_screen 
*pscreen,
return 0;
 }
 
+int
+nv50_screen_get_driver_query_group_info(struct pipe_screen *pscreen,
+unsigned id,
+struct pipe_driver_query_group_info 
*info)
+{
+   struct nv50_screen *screen = nv50_screen(pscreen);
+   int count = 0;
+
+   // TODO: Check DRM version when nvif will be merged in libdrm!
+   if (screen->base.perfmon) {
+  count++; /* NV50_HW_PM_QUERY_GROUP */
+   }
+
+   if (!info)
+  return count;
+
+   if (id == NV50_HW_PM_QUERY_GROUP) {
+  if (screen->base.perfmon) {
+ info->name = "Global performance counters";
+ info->type = PIPE_DRIVER_QUERY_GROUP_TYPE_GPU;
+ info->num_queries = NV50_HW_PM_QUERY_COUNT;
+ info->max_active_queries = 1; /* TODO: get rid of this limitation! */
+ return 1;
+  }
+   }
+
+   /* user asked for info about non-existing query group */
+   info->name = "this_is_not_the_query_group_you_are_looking_for";
+   info->max_active_queries = 0;
+   info->num_queries = 0;
+   info->type = 0;
+   return 0;
+}
+
 void
 nv50_init_query_functions(struct nv50_context *nv50)
 {
diff --git a/src/gallium/drivers/nouveau/nv50/nv50_screen.c 
b/src/gallium/drivers/nouveau/nv50/nv50_screen.c
index f07798e..dfe20c9 100644
--- a/src/gallium/drivers/nouveau/nv50/nv50_screen.c
+++ b/src/gallium/drivers/nouveau/nv50/nv50_screen.c
@@ -746,6 +746,7 @@ nv50_screen_create(struct nouveau_device *dev)
pscreen->get_shader_param = nv50_screen_get_shader_param;
pscreen->get_paramf = nv50_screen_get_paramf;
pscreen->get_driver_query_info = nv50_screen_get_driver_query_info;
+   pscreen->get_driver_query_group_info = 
nv50_screen_get_driver_query_group_info;
 
nv50_screen_init_resource_functions(pscreen);
 
diff --git a/src/gallium/drivers/nouveau/nv50/nv50_screen.h 
b/src/gallium/drivers/nouveau/nv50/nv50_screen.h
index 69127c0..807ae0e 100644
--- a/src/gallium/drivers/nouveau/nv50/nv50_screen.h
+++ b/src/gallium/drivers/nouveau/nv50/nv50_screen.h
@@ -114,6 +114,9 @@ nv50_screen(struct pipe_screen *screen)
return (struct nv50_screen *)screen;
 }
 
+/* Hardware global performance counters groups. */
+#define NV50_HW_PM_QUERY_GROUP 0
+
 /* Hardware global performance counters. */
 #define NV50_HW_PM_QUERY_COUNT  24
 #define NV50_HW_PM_QUERY(i)(PIPE_QUERY_DRIVER_SPECIFIC + (i))
@@ -146,6 +149,9 @@ nv50_screen(struct pipe_screen *screen)
 int nv50_screen_get_driver_query_info(struct pipe_screen *, unsigned,
   struct pipe_driver_query_info *);
 
+int nv50_screen_get_driver_query_group_info(struct pipe_screen *, unsigned,
+struct 
pipe_driver_query_group_info *);
+
 boolean nv50_blitter_create(struct nv50_screen *);
 void nv50_blitter_destroy(struct nv50_screen *);
 
-- 
2.4.4

___
Nouveau mailing list
Nouveau@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/nouveau


[Nouveau] [RFC PATCH 6/8] nv50: add support for compute/graphics global performance counters

2015-06-22 Thread Samuel Pitoiset
This commit adds support for both compute and graphics global
performance counters which have been reverse engineered with
CUPTI (Linux) and PerfKit (Windows).

Currently, only one query type can be monitored at the same time because
the Gallium's HUD doesn't fit pretty well. This will be improved later.

Signed-off-by: Samuel Pitoiset 
---
 src/gallium/drivers/nouveau/nv50/nv50_query.c  | 1057 +++-
 src/gallium/drivers/nouveau/nv50/nv50_screen.h |   35 +
 2 files changed, 1087 insertions(+), 5 deletions(-)

diff --git a/src/gallium/drivers/nouveau/nv50/nv50_query.c 
b/src/gallium/drivers/nouveau/nv50/nv50_query.c
index 1162110..b9d2914 100644
--- a/src/gallium/drivers/nouveau/nv50/nv50_query.c
+++ b/src/gallium/drivers/nouveau/nv50/nv50_query.c
@@ -27,6 +27,8 @@
 #include "nv50/nv50_context.h"
 #include "nv_object.xml.h"
 
+#include "nouveau_perfmon.h"
+
 #define NV50_QUERY_STATE_READY   0
 #define NV50_QUERY_STATE_ACTIVE  1
 #define NV50_QUERY_STATE_ENDED   2
@@ -51,10 +53,25 @@ struct nv50_query {
boolean is64bit;
struct nouveau_mm_allocation *mm;
struct nouveau_fence *fence;
+   struct nouveau_object *perfdom;
 };
 
 #define NV50_QUERY_ALLOC_SPACE 256
 
+#ifdef DEBUG
+static void nv50_hw_pm_dump_perfdom(struct nvif_perfdom_v0 *args);
+#endif
+
+static boolean
+nv50_hw_pm_query_create(struct nv50_context *, struct nv50_query *);
+static void
+nv50_hw_pm_query_destroy(struct nv50_context *, struct nv50_query *);
+static boolean
+nv50_hw_pm_query_begin(struct nv50_context *, struct nv50_query *);
+static void nv50_hw_pm_query_end(struct nv50_context *, struct nv50_query *);
+static boolean nv50_hw_pm_query_result(struct nv50_context *,
+struct nv50_query *, boolean, void *);
+
 static INLINE struct nv50_query *
 nv50_query(struct pipe_query *pipe)
 {
@@ -96,12 +113,18 @@ nv50_query_allocate(struct nv50_context *nv50, struct 
nv50_query *q, int size)
 static void
 nv50_query_destroy(struct pipe_context *pipe, struct pipe_query *pq)
 {
+   struct nv50_context *nv50 = nv50_context(pipe);
+   struct nv50_query *q = nv50_query(pq);
+
if (!pq)
   return;
 
-   nv50_query_allocate(nv50_context(pipe), nv50_query(pq), 0);
-   nouveau_fence_ref(NULL, &nv50_query(pq)->fence);
-   FREE(nv50_query(pq));
+   if ((q->type >= NV50_HW_PM_QUERY(0) && q->type <= NV50_HW_PM_QUERY_LAST))
+  nv50_hw_pm_query_destroy(nv50, q);
+
+   nv50_query_allocate(nv50, q, 0);
+   nouveau_fence_ref(NULL, &q->fence);
+   FREE(q);
 }
 
 static struct pipe_query *
@@ -130,6 +153,11 @@ nv50_query_create(struct pipe_context *pipe, unsigned 
type, unsigned index)
   q->data -= 32 / sizeof(*q->data); /* we advance before query_begin ! */
}
 
+   if ((q->type >= NV50_HW_PM_QUERY(0) && q->type <= NV50_HW_PM_QUERY_LAST)) {
+  if (!nv50_hw_pm_query_create(nv50, q))
+ return NULL;
+   }
+
return (struct pipe_query *)q;
 }
 
@@ -154,6 +182,7 @@ nv50_query_begin(struct pipe_context *pipe, struct 
pipe_query *pq)
struct nv50_context *nv50 = nv50_context(pipe);
struct nouveau_pushbuf *push = nv50->base.pushbuf;
struct nv50_query *q = nv50_query(pq);
+   boolean ret = TRUE;
 
if (!pq)
   return FALSE;
@@ -211,10 +240,13 @@ nv50_query_begin(struct pipe_context *pipe, struct 
pipe_query *pq)
   nv50_query_get(push, q, 0x10, 0x5002);
   break;
default:
+  if ((q->type >= NV50_HW_PM_QUERY(0) && q->type <= 
NV50_HW_PM_QUERY_LAST)) {
+ ret = nv50_hw_pm_query_begin(nv50, q);
+  }
   break;
}
q->state = NV50_QUERY_STATE_ACTIVE;
-   return true;
+   return ret;
 }
 
 static void
@@ -274,7 +306,9 @@ nv50_query_end(struct pipe_context *pipe, struct pipe_query 
*pq)
   q->state = NV50_QUERY_STATE_READY;
   break;
default:
-  assert(0);
+  if ((q->type >= NV50_HW_PM_QUERY(0) && q->type <= 
NV50_HW_PM_QUERY_LAST)) {
+ nv50_hw_pm_query_end(nv50, q);
+  }
   break;
}
 
@@ -309,6 +343,10 @@ nv50_query_result(struct pipe_context *pipe, struct 
pipe_query *pq,
if (!pq)
   return FALSE;
 
+   if ((q->type >= NV50_HW_PM_QUERY(0) && q->type <= NV50_HW_PM_QUERY_LAST)) {
+  return nv50_hw_pm_query_result(nv50, q, wait, result);
+   }
+
if (q->state != NV50_QUERY_STATE_READY)
   nv50_query_update(q);
 
@@ -488,6 +526,1015 @@ nva0_so_target_save_offset(struct pipe_context *pipe,
nv50_query_end(pipe, targ->pq);
 }
 
+/* === HARDWARE GLOBAL PERFORMANCE COUNTERS for NV50 === */
+
+struct nv50_hw_pm_source_cfg
+{
+   const char *name;
+   uint64_t value;
+};
+
+struct nv50_hw_pm_signal_cfg
+{
+   const char *name;
+   const struct nv50_hw_pm_source_cfg src[8];
+};
+
+struct nv50_hw_pm_counter_cfg
+{
+   uint16_t logic_op;
+   const struct nv50_hw_pm_signal_cfg sig[4];
+};
+

[Nouveau] [PATCH 2/2] pm/gk104: add compute signals/sources

2015-06-19 Thread Samuel Pitoiset
These signals and sources have been reverse engineered from CUPTI
(Linux). Graphics signals exposed by PerfKit (Windows only) will be
added later. I need to reverse engineer them and it's a bit painful.

Signed-off-by: Samuel Pitoiset 
---
 drm/nouveau/nvkm/engine/pm/gf100.h |  1 +
 drm/nouveau/nvkm/engine/pm/gf117.c |  8 +++-
 drm/nouveau/nvkm/engine/pm/gk104.c | 85 ++
 3 files changed, 93 insertions(+), 1 deletion(-)

diff --git a/drm/nouveau/nvkm/engine/pm/gf100.h 
b/drm/nouveau/nvkm/engine/pm/gf100.h
index 40ced89..d73f0ca 100644
--- a/drm/nouveau/nvkm/engine/pm/gf100.h
+++ b/drm/nouveau/nvkm/engine/pm/gf100.h
@@ -27,5 +27,6 @@ int gf100_pm_fini(struct nvkm_object *, bool);
 extern const struct nvkm_specdom gf100_pm_gpc[];
 
 extern const struct nvkm_specsrc gf100_pmfb_sources[];
+extern const struct nvkm_specsrc gf117_pbfb_sources[];
 
 #endif
diff --git a/drm/nouveau/nvkm/engine/pm/gf117.c 
b/drm/nouveau/nvkm/engine/pm/gf117.c
index 911ff3f..01d3a48 100644
--- a/drm/nouveau/nvkm/engine/pm/gf117.c
+++ b/drm/nouveau/nvkm/engine/pm/gf117.c
@@ -39,7 +39,7 @@ gf117_pmfb_sources[] = {
{}
 };
 
-static const struct nvkm_specsrc
+const struct nvkm_specsrc
 gf117_pbfb_sources[] = {
{ 0x110100, (const struct nvkm_specmux[]) {
{ 0x1, 0, "unk0" },
@@ -47,6 +47,12 @@ gf117_pbfb_sources[] = {
{ 0x3, 8, "unk8" },
{}
}, "pbfb0_pm_unk100" },
+{ 0x10f100, (const struct nvkm_specmux[]) {
+   { 0x1, 0, "unk0" },
+   { 0xf, 4, "unk4" },
+   { 0x3, 8, "unk8" },
+   {}
+   }, "pbfb_broadcast_pm_unk100" },
{}
 };
 
diff --git a/drm/nouveau/nvkm/engine/pm/gk104.c 
b/drm/nouveau/nvkm/engine/pm/gk104.c
index 7462dff..5067f72 100644
--- a/drm/nouveau/nvkm/engine/pm/gk104.c
+++ b/drm/nouveau/nvkm/engine/pm/gk104.c
@@ -23,6 +23,52 @@
  */
 #include "gf100.h"
 
+static const struct nvkm_specsrc
+gk104_pmfb_sources[] = {
+   { 0x140028, (const struct nvkm_specmux[]) {
+   { 0x3fff, 0, "unk0" },
+   { 0x7, 16, "unk16" },
+   { 0x3, 24, "unk24" },
+   { 0x2, 28, "unk28" },
+   {}
+   }, "pmfb0_pm_unk28" },
+   { 0x14125c, (const struct nvkm_specmux[]) {
+   { 0x3fff, 0, "unk0" },
+   {}
+   }, "pmfb0_subp0_pm_unk25c" },
+   { 0x14165c, (const struct nvkm_specmux[]) {
+   { 0x3fff, 0, "unk0" },
+   {}
+   }, "pmfb0_subp1_pm_unk25c" },
+   { 0x141a5c, (const struct nvkm_specmux[]) {
+   { 0x3fff, 0, "unk0" },
+   {}
+   }, "pmfb0_subp2_pm_unk25c" },
+   { 0x141e5c, (const struct nvkm_specmux[]) {
+   { 0x3fff, 0, "unk0" },
+   {}
+   }, "pmfb0_subp3_pm_unk25c" },
+   {}
+};
+
+static const struct nvkm_specsrc
+gk104_tex_sources[] = {
+   { 0x5042c0, (const struct nvkm_specmux[]) {
+   { 0xf, 0, "sel0", true },
+   { 0x7, 8, "sel1", true },
+   {}
+   }, "pgraph_gpc0_tpc0_tex_pm_mux_c_d" },
+   { 0x5042c8, (const struct nvkm_specmux[]) {
+   { 0x1f, 0, "sel", true },
+   {}
+   }, "pgraph_gpc0_tpc0_tex_pm_unkc8" },
+   { 0x5042b8, (const struct nvkm_specmux[]) {
+   { 0xff, 0, "sel", true },
+   {}
+   }, "pgraph_gpc0_tpc0_tex_pm_unkb8" },
+   {}
+};
+
 static const struct nvkm_specdom
 gk104_pm_hub[] = {
{ 0x60, (const struct nvkm_specsig[]) {
@@ -69,12 +115,51 @@ gk104_pm_gpc[] = {
{ 0xc7, "gpc00_user_0" },
{}
}, &gf100_perfctr_func },
+   { 0x20, (const struct nvkm_specsig[]) {
+   {}
+   }, &gf100_perfctr_func },
+   { 0x20, (const struct nvkm_specsig[]) {
+   { 0x00, "gpc02_tex_00", gk104_tex_sources },
+   { 0x01, "gpc02_tex_01", gk104_tex_sources },
+   { 0x02, "gpc02_tex_02", gk104_tex_sources },
+   { 0x03, "gpc02_tex_03", gk104_tex_sources },
+   { 0x04, "gpc02_tex_04", gk104_tex_sources },
+   { 0x05, "gpc02_tex_05", gk104_tex_sources },
+   { 0

[Nouveau] [PATCH 1/2] pm/gk104: re-use gf100_pm_ctor()

2015-06-19 Thread Samuel Pitoiset
gk104_pm_ctor() is equal to gf100_pm_ctor().

Signed-off-by: Samuel Pitoiset 
---
 drm/nouveau/include/nvkm/engine/pm.h   |  2 +-
 drm/nouveau/nvkm/engine/device/gk104.c |  8 ++---
 drm/nouveau/nvkm/engine/pm/gk104.c | 60 +-
 3 files changed, 14 insertions(+), 56 deletions(-)

diff --git a/drm/nouveau/include/nvkm/engine/pm.h 
b/drm/nouveau/include/nvkm/engine/pm.h
index ed36daf..c4c704b 100644
--- a/drm/nouveau/include/nvkm/engine/pm.h
+++ b/drm/nouveau/include/nvkm/engine/pm.h
@@ -29,6 +29,6 @@ extern struct nvkm_oclass *gt215_pm_oclass;
 extern struct nvkm_oclass *gf100_pm_oclass;
 extern struct nvkm_oclass *gf108_pm_oclass;
 extern struct nvkm_oclass *gf117_pm_oclass;
-extern struct nvkm_oclass gk104_pm_oclass;
+extern struct nvkm_oclass *gk104_pm_oclass;
 extern struct nvkm_oclass gk110_pm_oclass;
 #endif
diff --git a/drm/nouveau/nvkm/engine/device/gk104.c 
b/drm/nouveau/nvkm/engine/device/gk104.c
index 6a9483f..2b1fce2 100644
--- a/drm/nouveau/nvkm/engine/device/gk104.c
+++ b/drm/nouveau/nvkm/engine/device/gk104.c
@@ -91,7 +91,7 @@ gk104_identify(struct nvkm_device *device)
device->oclass[NVDEV_ENGINE_MSVLD  ] = &gk104_msvld_oclass;
device->oclass[NVDEV_ENGINE_MSPDEC ] = &gk104_mspdec_oclass;
device->oclass[NVDEV_ENGINE_MSPPP  ] = &gf100_msppp_oclass;
-   device->oclass[NVDEV_ENGINE_PM ] = &gk104_pm_oclass;
+   device->oclass[NVDEV_ENGINE_PM ] = gk104_pm_oclass;
break;
case 0xe7:
device->cname = "GK107";
@@ -125,7 +125,7 @@ gk104_identify(struct nvkm_device *device)
device->oclass[NVDEV_ENGINE_MSVLD  ] = &gk104_msvld_oclass;
device->oclass[NVDEV_ENGINE_MSPDEC ] = &gk104_mspdec_oclass;
device->oclass[NVDEV_ENGINE_MSPPP  ] = &gf100_msppp_oclass;
-   device->oclass[NVDEV_ENGINE_PM ] = &gk104_pm_oclass;
+   device->oclass[NVDEV_ENGINE_PM ] = gk104_pm_oclass;
break;
case 0xe6:
device->cname = "GK106";
@@ -159,7 +159,7 @@ gk104_identify(struct nvkm_device *device)
device->oclass[NVDEV_ENGINE_MSVLD  ] = &gk104_msvld_oclass;
device->oclass[NVDEV_ENGINE_MSPDEC ] = &gk104_mspdec_oclass;
device->oclass[NVDEV_ENGINE_MSPPP  ] = &gf100_msppp_oclass;
-   device->oclass[NVDEV_ENGINE_PM ] = &gk104_pm_oclass;
+   device->oclass[NVDEV_ENGINE_PM ] = gk104_pm_oclass;
break;
case 0xea:
device->cname = "GK20A";
@@ -179,7 +179,7 @@ gk104_identify(struct nvkm_device *device)
device->oclass[NVDEV_ENGINE_SW ] =  gf100_sw_oclass;
device->oclass[NVDEV_ENGINE_GR ] =  gk20a_gr_oclass;
device->oclass[NVDEV_ENGINE_CE2] = &gk104_ce2_oclass;
-   device->oclass[NVDEV_ENGINE_PM ] = &gk104_pm_oclass;
+   device->oclass[NVDEV_ENGINE_PM ] = gk104_pm_oclass;
device->oclass[NVDEV_SUBDEV_VOLT   ] = &gk20a_volt_oclass;
device->oclass[NVDEV_SUBDEV_PMU] =  gk20a_pmu_oclass;
break;
diff --git a/drm/nouveau/nvkm/engine/pm/gk104.c 
b/drm/nouveau/nvkm/engine/pm/gk104.c
index 3565f29..7462dff 100644
--- a/drm/nouveau/nvkm/engine/pm/gk104.c
+++ b/drm/nouveau/nvkm/engine/pm/gk104.c
@@ -85,58 +85,16 @@ gk104_pm_part[] = {
{}
 };
 
-static int
-gk104_pm_ctor(struct nvkm_object *parent, struct nvkm_object *engine,
- struct nvkm_oclass *oclass, void *data, u32 size,
- struct nvkm_object **pobject)
-{
-   struct gf100_pm_priv *priv;
-   u32 mask;
-   int ret;
-
-   ret = nvkm_pm_create(parent, engine, oclass, &priv);
-   *pobject = nv_object(priv);
-   if (ret)
-   return ret;
-
-   /* HUB */
-   ret = nvkm_perfdom_new(&priv->base, "hub", 0, 0x1b, 0, 0x200,
-  gk104_pm_hub);
-   if (ret)
-   return ret;
-
-   /* GPC */
-   mask  = (1 << nv_rd32(priv, 0x022430)) - 1;
-   mask &= ~nv_rd32(priv, 0x022504);
-   mask &= ~nv_rd32(priv, 0x022584);
-
-   ret = nvkm_perfdom_new(&priv->base, "gpc", mask, 0x18,
-  0x1000, 0x200, gk104_pm_gpc);
-   if (ret)
-   return ret;
-
-   /* PART */
-   mask  = (1 << nv_rd32(priv, 0x022438)) - 1;
-   mask &= ~nv_rd32(priv, 0x022548);
-   mask &= ~nv_rd32(priv, 0x0225c8);
-
-   ret = nvkm_perfdom_new(&priv->base, "part", mask, 0x1a,
-  0x1000, 0x200, gk104_pm_part);
-   if (ret)
-   return re

[Nouveau] [PATCH 2/2] pm/nv40: rename pcounter domains to 'pc' instead of 'pm'

2015-06-19 Thread Samuel Pitoiset
This trivial patch makes thing more consistent since hardware signals
names are prefixed by 'pcXX'.

Signed-off-by: Samuel Pitoiset 
---
 drm/nouveau/nvkm/engine/pm/nv40.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drm/nouveau/nvkm/engine/pm/nv40.c 
b/drm/nouveau/nvkm/engine/pm/nv40.c
index 1c6d1ca..5a87f3a 100644
--- a/drm/nouveau/nvkm/engine/pm/nv40.c
+++ b/drm/nouveau/nvkm/engine/pm/nv40.c
@@ -108,7 +108,7 @@ nv40_pm_ctor(struct nvkm_object *parent, struct nvkm_object 
*engine,
if (ret)
return ret;
 
-   ret = nvkm_perfdom_new(&priv->base, "pm", 0, 0, 0, 4, mclass->doms);
+   ret = nvkm_perfdom_new(&priv->base, "pc", 0, 0, 0, 4, mclass->doms);
if (ret)
return ret;
 
-- 
2.4.3

___
Nouveau mailing list
Nouveau@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/nouveau


[Nouveau] [PATCH 1/2] pm: expose name of domains

2015-06-19 Thread Samuel Pitoiset
This is going to be very useful for GF100+ because each GPC can
have its own domain of counters.

Signed-off-by: Samuel Pitoiset 
---
 drm/nouveau/include/nvif/class.h  | 1 +
 drm/nouveau/nvkm/engine/pm/base.c | 1 +
 2 files changed, 2 insertions(+)

diff --git a/drm/nouveau/include/nvif/class.h b/drm/nouveau/include/nvif/class.h
index 3b7f49f..59d5983 100644
--- a/drm/nouveau/include/nvif/class.h
+++ b/drm/nouveau/include/nvif/class.h
@@ -262,6 +262,7 @@ struct nvif_perfmon_query_domain_v0 {
__u8  iter;
__u16 signal_nr;
__u8  pad05[2];
+   char  name[64];
 };
 
 struct nvif_perfmon_query_signal_v0 {
diff --git a/drm/nouveau/nvkm/engine/pm/base.c 
b/drm/nouveau/nvkm/engine/pm/base.c
index 7866e22..94991d6 100644
--- a/drm/nouveau/nvkm/engine/pm/base.c
+++ b/drm/nouveau/nvkm/engine/pm/base.c
@@ -454,6 +454,7 @@ nvkm_perfmon_mthd_query_domain(struct nvkm_object *object, 
void *data, u32 size)
 
args->v0.id = di;
args->v0.signal_nr  = nvkm_perfdom_count_perfsig(dom);
+   strncpy(args->v0.name, dom->name, sizeof(args->v0.name));
 
/* Currently only global counters (PCOUNTER) are implemented
 * but this will be different for local counters (MP). */
-- 
2.4.3

___
Nouveau mailing list
Nouveau@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/nouveau


Re: [Nouveau] [PATCH RFC 05/20] pm: reorganize the nvif interface

2015-06-14 Thread Samuel Pitoiset



On 06/14/2015 04:32 AM, Ben Skeggs wrote:

On 10 June 2015 at 07:53, Samuel Pitoiset  wrote:


On 06/09/2015 12:02 AM, Ben Skeggs wrote:

On 8 June 2015 at 06:40, Samuel Pitoiset 
wrote:

This commit introduces the NVIF_IOCTL_NEW_V0_PERFMON class which will be
used in order to query domains, signals and sources. This separates the
querying and the counting interface.

Hey Samuel,

I've merged patches 1-4 already, I've got some comments on this one,
but after they're solved I'm happy to merge up to (and including)
patch 18.  Patches 19/20, I need to think about some more.


Hey Ben,

Thanks for reviewing this series so quickly. :-)



Signed-off-by: Samuel Pitoiset 
---
   bin/nv_perfmon.c  | 12 ++--
   drm/nouveau/include/nvif/class.h  | 26 --
   drm/nouveau/include/nvif/ioctl.h  |  5 +++--
   drm/nouveau/nvkm/engine/pm/base.c | 38
--
   4 files changed, 57 insertions(+), 24 deletions(-)

diff --git a/bin/nv_perfmon.c b/bin/nv_perfmon.c
index a8c5838..30a3138 100644
--- a/bin/nv_perfmon.c
+++ b/bin/nv_perfmon.c
@@ -600,7 +600,7 @@ main(int argc, char **argv)
  const char *cfg = NULL;
  const char *dbg = "error";
  u64 dev = ~0ULL;
-   struct nvif_perfctr_query_v0 args = {};
+   struct nvif_perfmon_query_signal_v0 args = {};
  struct nvif_client *client;
  struct nvif_object object;
  int ret, c, k;
@@ -644,15 +644,14 @@ main(int argc, char **argv)
  }

  ret = nvif_object_init(nvif_object(device), NULL, 0xdeadbeef,
-  NVIF_IOCTL_NEW_V0_PERFCTR,
-  &(struct nvif_perfctr_v0) {
-  }, sizeof(struct nvif_perfctr_v0),
&object);
+  NVIF_IOCTL_NEW_V0_PERFMON, NULL, 0,
&object);
  assert(ret == 0);
  do {
  u32 prev_iter = args.iter;

  args.name[0] = '\0';
-   ret = nvif_mthd(&object, NVIF_PERFCTR_V0_QUERY, &args,
sizeof(args));
+   ret = nvif_mthd(&object, NVIF_PERFMON_V0_QUERY_SIGNAL,
+   &args, sizeof(args));
  assert(ret == 0);

  if (prev_iter) {
@@ -663,7 +662,8 @@ main(int argc, char **argv)
  args.iter = prev_iter;
  strncpy(signals[nr_signals - 1], args.name,
  sizeof(args.name));
-   ret = nvif_mthd(&object, NVIF_PERFCTR_V0_QUERY,
&args, sizeof(args));
+   ret = nvif_mthd(&object,
NVIF_PERFMON_V0_QUERY_SIGNAL,
+   &args, sizeof(args));
  assert(ret == 0);
  }
  } while (args.iter != 0x);
diff --git a/drm/nouveau/include/nvif/class.h
b/drm/nouveau/include/nvif/class.h
index 64f8b2f..11935a0 100644
--- a/drm/nouveau/include/nvif/class.h
+++ b/drm/nouveau/include/nvif/class.h
@@ -251,6 +251,20 @@ struct gf110_dma_v0 {
* perfmon

**/

+#define NVIF_PERFMON_V0_QUERY_SIGNAL
0x00
+
+struct nvif_perfmon_query_signal_v0 {
+   __u8  version;
+   __u8  pad01[3];
+   __u32 iter;
+   char  name[64];
+};
+
+

+/***
+ * perfctr
+
**/
+
   struct nvif_perfctr_v0 {
  __u8  version;
  __u8  pad01[1];
@@ -259,16 +273,8 @@ struct nvif_perfctr_v0 {
  char  name[4][64];
   };

-#define NVIF_PERFCTR_V0_QUERY
0x00
-#define NVIF_PERFCTR_V0_SAMPLE
0x01
-#define NVIF_PERFCTR_V0_READ
0x02
-
-struct nvif_perfctr_query_v0 {
-   __u8  version;
-   __u8  pad01[3];
-   __u32 iter;
-   char  name[64];
-};
+#define NVIF_PERFCTR_V0_SAMPLE
0x00
+#define NVIF_PERFCTR_V0_READ
0x01

   struct nvif_perfctr_sample {
   };
diff --git a/drm/nouveau/include/nvif/ioctl.h
b/drm/nouveau/include/nvif/ioctl.h
index 4cd8e32..517cd27 100644
--- a/drm/nouveau/include/nvif/ioctl.h
+++ b/drm/nouveau/include/nvif/ioctl.h
@@ -49,8 +49,9 @@ struct nvif_ioctl_new_v0 {
  __u64 token;
  __u32 handle;
   /* these class numbers are made up by us, and not nvidia-assigned */
-#define NVIF_IOCTL_NEW_V0_PERFCTR
0x
-#define NVIF_IOCTL_NEW_V0_CONTROL
0xfffe
+#define NVIF_IOCTL_NEW_V0_PERFMON
0x
+#define NVIF_IOCTL_NEW_V0_PERFCTR
0xfffe
+#define NVIF_IOCTL_NEW_V0_CONTROL
0xfffd

It doesn't matter this time, because we're technically breaking ABI
already anyway and current userspace won't be effected, but best to
avoid changing class numbers like this :)  It's fine this time though.


Sure, since the nvif interface is still not exposed th

[Nouveau] [PATCH 2/2] pm: some fixes related to sources

2015-06-14 Thread Samuel Pitoiset
Signed-off-by: Samuel Pitoiset 
---

This patch should be squashed with "pm: allow the userspace to configure 
sources".

 drm/nouveau/nvkm/engine/pm/base.c | 21 -
 1 file changed, 16 insertions(+), 5 deletions(-)

diff --git a/drm/nouveau/nvkm/engine/pm/base.c 
b/drm/nouveau/nvkm/engine/pm/base.c
index f505a11..7866e22 100644
--- a/drm/nouveau/nvkm/engine/pm/base.c
+++ b/drm/nouveau/nvkm/engine/pm/base.c
@@ -154,6 +154,8 @@ nvkm_perfsrc_enable(struct nvkm_pm *ppm, struct 
nvkm_perfctr *ctr)
 
/* enable the source */
nv_mask(ppm, src->addr, mask, value);
+   nv_debug(ppm, "enabled source 0x%08x 0x%08x 0x%08x\n",
+src->addr, mask, value);
}
}
return 0;
@@ -165,6 +167,7 @@ nvkm_perfsrc_disable(struct nvkm_pm *ppm, struct 
nvkm_perfctr *ctr)
struct nvkm_perfdom *dom = NULL;
struct nvkm_perfsig *sig;
struct nvkm_perfsrc *src;
+   u32 mask;
int i, j;
 
for (i = 0; i < 4 && ctr->signal[i]; i++) {
@@ -178,8 +181,16 @@ nvkm_perfsrc_disable(struct nvkm_pm *ppm, struct 
nvkm_perfctr *ctr)
if (!src)
return -EINVAL;
 
+   /* unset enable bit if needed */
+   mask = 0x;
+   if (src->enable)
+   mask = 0x8000;
+   mask |= (src->mask << src->shift);
+
/* disable the source */
-   nv_mask(ppm, src->addr, src->mask << src->shift, 0);
+   nv_mask(ppm, src->addr, mask, 0);
+   nv_debug(ppm, "disabled source 0x%08x 0x%08x\n",
+src->addr, mask);
}
}
return 0;
@@ -309,7 +320,7 @@ nvkm_perfdom_dtor(struct nvkm_object *object)
 }
 
 static int
-nvkm_perfctr_new(struct nvkm_perfdom *dom, int slot,
+nvkm_perfctr_new(struct nvkm_perfdom *dom, int slot, uint8_t domain,
 struct nvkm_perfsig *signal[4], uint64_t source[4][8],
 uint16_t logic_op, struct nvkm_perfctr **pctr)
 {
@@ -323,6 +334,7 @@ nvkm_perfctr_new(struct nvkm_perfdom *dom, int slot,
if (!ctr)
return -ENOMEM;
 
+   ctr->domain   = domain;
ctr->logic_op = logic_op;
ctr->slot = slot;
for (i = 0; i < 4; i++) {
@@ -361,7 +373,7 @@ nvkm_perfdom_ctor(struct nvkm_object *parent, struct 
nvkm_object *engine,
 
for (c = 0; c < ARRAY_SIZE(args->v0.ctr); c++) {
struct nvkm_perfsig *sig[4] = {};
-   u64 src[4][8];
+   u64 src[4][8] = {};
 
for (s = 0; s < ARRAY_SIZE(args->v0.ctr[c].signal); s++) {
sig[s] = nvkm_perfsig_find(ppm, args->v0.domain,
@@ -378,11 +390,10 @@ nvkm_perfdom_ctor(struct nvkm_object *parent, struct 
nvkm_object *engine,
}
}
 
-   ret = nvkm_perfctr_new(sdom, c, sig, src,
+   ret = nvkm_perfctr_new(sdom, c, args->v0.domain, sig, src,
   args->v0.ctr[c].logic_op, &ctr[c]);
if (ret)
return ret;
-   ctr[c]->domain = args->v0.domain;
}
 
if (!sdom)
-- 
2.4.2

___
Nouveau mailing list
Nouveau@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/nouveau


[Nouveau] [PATCH 1/2] pm: fix signals/sources for GT200+

2015-06-14 Thread Samuel Pitoiset
Signed-off-by: Samuel Pitoiset 
---

This patch should be squashed with "pm/nv50: add compute and graphics 
signals/sources".

 drm/nouveau/nvkm/engine/pm/gt200.c | 8 
 drm/nouveau/nvkm/engine/pm/gt215.c | 3 +--
 2 files changed, 5 insertions(+), 6 deletions(-)

diff --git a/drm/nouveau/nvkm/engine/pm/gt200.c 
b/drm/nouveau/nvkm/engine/pm/gt200.c
index 220a027..e92f9c7 100644
--- a/drm/nouveau/nvkm/engine/pm/gt200.c
+++ b/drm/nouveau/nvkm/engine/pm/gt200.c
@@ -26,7 +26,7 @@
 const struct nvkm_specsrc
 gt200_crop_sources[] = {
{ 0x407008, (const struct nvkm_specmux[]) {
-   { 0x7, 0, "sel0", true },
+   { 0xf, 0, "sel0", true },
{ 0x1f, 16, "sel1", true },
{}
}, "pgraph_rop0_crop_pm_mux" },
@@ -45,7 +45,7 @@ gt200_prop_sources[] = {
 const struct nvkm_specsrc
 gt200_tex_sources[] = {
{ 0x408508, (const struct nvkm_specmux[]) {
-   { 0x3fff, 0, "unk0" },
+   { 0xf, 0, "unk0" },
{}
}, "pgraph_tpc0_tex_unk08" },
{}
@@ -94,7 +94,7 @@ gt200_pm[] = {
{ 0x5d, "pc01_vfetch_17", g84_vfetch_sources },
{ 0x5e, "pc01_vfetch_18", g84_vfetch_sources },
{ 0x5f, "pc01_vfetch_19", g84_vfetch_sources },
- { 0x07, "pc01_zcull_00", nv50_zcull_sources },
+   { 0x07, "pc01_zcull_00", nv50_zcull_sources },
{ 0x08, "pc01_zcull_01", nv50_zcull_sources },
{ 0x09, "pc01_zcull_02", nv50_zcull_sources },
{ 0x0a, "pc01_zcull_03", nv50_zcull_sources },
@@ -105,7 +105,7 @@ gt200_pm[] = {
{ 0xec, "pc01_trailer" },
{}
}, &nv40_perfctr_func },
-   { 0xe0, (const struct nvkm_specsig[]) {
+   { 0xf0, (const struct nvkm_specsig[]) {
{ 0x55, "pc02_crop_00", gt200_crop_sources },
{ 0x56, "pc02_crop_01", gt200_crop_sources },
{ 0x57, "pc02_crop_02", gt200_crop_sources },
diff --git a/drm/nouveau/nvkm/engine/pm/gt215.c 
b/drm/nouveau/nvkm/engine/pm/gt215.c
index b5542dc..f5eae63 100644
--- a/drm/nouveau/nvkm/engine/pm/gt215.c
+++ b/drm/nouveau/nvkm/engine/pm/gt215.c
@@ -23,10 +23,9 @@
  */
 #include "nv40.h"
 
-// TODO: check for GT200
 static const struct nvkm_specsrc
 gt215_zcull_sources[] = {
-   { 0x4002ca4, (const struct nvkm_specmux[]) {
+   { 0x402ca4, (const struct nvkm_specmux[]) {
{ 0x7fff, 0, "unk0" },
{ 0xff, 24, "unk24" },
{}
-- 
2.4.2

___
Nouveau mailing list
Nouveau@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/nouveau


[Nouveau] [PATCH 1/2] pm/gf100: allow to share GPC, HUB and PART domains

2015-06-14 Thread Samuel Pitoiset
Signed-off-by: Samuel Pitoiset 
---
 drm/nouveau/include/nvkm/engine/pm.h   |  2 +-
 drm/nouveau/nvkm/engine/device/gf100.c | 18 +-
 drm/nouveau/nvkm/engine/pm/gf100.c | 22 +-
 drm/nouveau/nvkm/engine/pm/gf100.h | 11 +++
 4 files changed, 34 insertions(+), 19 deletions(-)

diff --git a/drm/nouveau/include/nvkm/engine/pm.h 
b/drm/nouveau/include/nvkm/engine/pm.h
index 82f1c7f..ce5d93e 100644
--- a/drm/nouveau/include/nvkm/engine/pm.h
+++ b/drm/nouveau/include/nvkm/engine/pm.h
@@ -26,7 +26,7 @@ extern struct nvkm_oclass *nv50_pm_oclass;
 extern struct nvkm_oclass *g84_pm_oclass;
 extern struct nvkm_oclass *gt200_pm_oclass;
 extern struct nvkm_oclass *gt215_pm_oclass;
-extern struct nvkm_oclass gf100_pm_oclass;
+extern struct nvkm_oclass *gf100_pm_oclass;
 extern struct nvkm_oclass gk104_pm_oclass;
 extern struct nvkm_oclass gk110_pm_oclass;
 #endif
diff --git a/drm/nouveau/nvkm/engine/device/gf100.c 
b/drm/nouveau/nvkm/engine/device/gf100.c
index 82b38d7..84a6abb 100644
--- a/drm/nouveau/nvkm/engine/device/gf100.c
+++ b/drm/nouveau/nvkm/engine/device/gf100.c
@@ -90,7 +90,7 @@ gf100_identify(struct nvkm_device *device)
device->oclass[NVDEV_ENGINE_CE0] = &gf100_ce0_oclass;
device->oclass[NVDEV_ENGINE_CE1] = &gf100_ce1_oclass;
device->oclass[NVDEV_ENGINE_DISP   ] =  gt215_disp_oclass;
-   device->oclass[NVDEV_ENGINE_PM ] = &gf100_pm_oclass;
+   device->oclass[NVDEV_ENGINE_PM ] = gf100_pm_oclass;
break;
case 0xc4:
device->cname = "GF104";
@@ -123,7 +123,7 @@ gf100_identify(struct nvkm_device *device)
device->oclass[NVDEV_ENGINE_CE0] = &gf100_ce0_oclass;
device->oclass[NVDEV_ENGINE_CE1] = &gf100_ce1_oclass;
device->oclass[NVDEV_ENGINE_DISP   ] =  gt215_disp_oclass;
-   device->oclass[NVDEV_ENGINE_PM ] = &gf100_pm_oclass;
+   device->oclass[NVDEV_ENGINE_PM ] = gf100_pm_oclass;
break;
case 0xc3:
device->cname = "GF106";
@@ -155,7 +155,7 @@ gf100_identify(struct nvkm_device *device)
device->oclass[NVDEV_ENGINE_MSPPP  ] = &gf100_msppp_oclass;
device->oclass[NVDEV_ENGINE_CE0] = &gf100_ce0_oclass;
device->oclass[NVDEV_ENGINE_DISP   ] =  gt215_disp_oclass;
-   device->oclass[NVDEV_ENGINE_PM ] = &gf100_pm_oclass;
+   device->oclass[NVDEV_ENGINE_PM ] = gf100_pm_oclass;
break;
case 0xce:
device->cname = "GF114";
@@ -188,7 +188,7 @@ gf100_identify(struct nvkm_device *device)
device->oclass[NVDEV_ENGINE_CE0] = &gf100_ce0_oclass;
device->oclass[NVDEV_ENGINE_CE1] = &gf100_ce1_oclass;
device->oclass[NVDEV_ENGINE_DISP   ] =  gt215_disp_oclass;
-   device->oclass[NVDEV_ENGINE_PM ] = &gf100_pm_oclass;
+   device->oclass[NVDEV_ENGINE_PM ] = gf100_pm_oclass;
break;
case 0xcf:
device->cname = "GF116";
@@ -220,7 +220,7 @@ gf100_identify(struct nvkm_device *device)
device->oclass[NVDEV_ENGINE_MSPPP  ] = &gf100_msppp_oclass;
device->oclass[NVDEV_ENGINE_CE0] = &gf100_ce0_oclass;
device->oclass[NVDEV_ENGINE_DISP   ] =  gt215_disp_oclass;
-   device->oclass[NVDEV_ENGINE_PM ] = &gf100_pm_oclass;
+   device->oclass[NVDEV_ENGINE_PM ] = gf100_pm_oclass;
break;
case 0xc1:
device->cname = "GF108";
@@ -252,7 +252,7 @@ gf100_identify(struct nvkm_device *device)
device->oclass[NVDEV_ENGINE_MSPPP  ] = &gf100_msppp_oclass;
device->oclass[NVDEV_ENGINE_CE0] = &gf100_ce0_oclass;
device->oclass[NVDEV_ENGINE_DISP   ] =  gt215_disp_oclass;
-   device->oclass[NVDEV_ENGINE_PM ] = &gf100_pm_oclass;
+   device->oclass[NVDEV_ENGINE_PM ] = gf100_pm_oclass;
break;
case 0xc8:
device->cname = "GF110";
@@ -285,7 +285,7 @@ gf100_identify(struct nvkm_device *device)
device->oclass[NVDEV_ENGINE_CE0] = &gf100_ce0_oclass;
device->oclass[NVDEV_ENGINE_CE1] = &gf100_ce1_oclass;
device->oclass[NVDEV_ENGINE_DISP   ] =  gt215_disp_oclass;
-   device->oclass[NVDEV_ENGINE_PM ] = &gf100_pm_oclass;
+   device->oclass[NVDEV_ENGINE_PM ] = gf100_pm_oclass;
break;
case 0xd9:
device->cname = 

[Nouveau] [PATCH 2/2] pm/gf100: add compute signals/sources

2015-06-14 Thread Samuel Pitoiset
These signals and sources have been reverse engineered from CUPTI
(Linux). Graphics signals exposed by PerfKit (Windows only) will be
added later. I need to reverse engineer them and it's a bit painful.

This commit also adds a new class for GF108 and GF117.

Signed-off-by: Samuel Pitoiset 
---
 drm/nouveau/include/nvkm/engine/pm.h   |  2 +
 drm/nouveau/nvkm/engine/device/gf100.c |  6 +--
 drm/nouveau/nvkm/engine/pm/Kbuild  |  2 +
 drm/nouveau/nvkm/engine/pm/gf100.c | 96 +-
 drm/nouveau/nvkm/engine/pm/gf100.h |  5 ++
 drm/nouveau/nvkm/engine/pm/gf108.c | 84 +
 drm/nouveau/nvkm/engine/pm/gf117.c | 92 
 7 files changed, 282 insertions(+), 5 deletions(-)
 create mode 100644 drm/nouveau/nvkm/engine/pm/gf108.c
 create mode 100644 drm/nouveau/nvkm/engine/pm/gf117.c

diff --git a/drm/nouveau/include/nvkm/engine/pm.h 
b/drm/nouveau/include/nvkm/engine/pm.h
index ce5d93e..ed36daf 100644
--- a/drm/nouveau/include/nvkm/engine/pm.h
+++ b/drm/nouveau/include/nvkm/engine/pm.h
@@ -27,6 +27,8 @@ extern struct nvkm_oclass *g84_pm_oclass;
 extern struct nvkm_oclass *gt200_pm_oclass;
 extern struct nvkm_oclass *gt215_pm_oclass;
 extern struct nvkm_oclass *gf100_pm_oclass;
+extern struct nvkm_oclass *gf108_pm_oclass;
+extern struct nvkm_oclass *gf117_pm_oclass;
 extern struct nvkm_oclass gk104_pm_oclass;
 extern struct nvkm_oclass gk110_pm_oclass;
 #endif
diff --git a/drm/nouveau/nvkm/engine/device/gf100.c 
b/drm/nouveau/nvkm/engine/device/gf100.c
index 84a6abb..65b151d 100644
--- a/drm/nouveau/nvkm/engine/device/gf100.c
+++ b/drm/nouveau/nvkm/engine/device/gf100.c
@@ -252,7 +252,7 @@ gf100_identify(struct nvkm_device *device)
device->oclass[NVDEV_ENGINE_MSPPP  ] = &gf100_msppp_oclass;
device->oclass[NVDEV_ENGINE_CE0] = &gf100_ce0_oclass;
device->oclass[NVDEV_ENGINE_DISP   ] =  gt215_disp_oclass;
-   device->oclass[NVDEV_ENGINE_PM ] = gf100_pm_oclass;
+   device->oclass[NVDEV_ENGINE_PM ] = gf108_pm_oclass;
break;
case 0xc8:
device->cname = "GF110";
@@ -317,7 +317,7 @@ gf100_identify(struct nvkm_device *device)
device->oclass[NVDEV_ENGINE_MSPPP  ] = &gf100_msppp_oclass;
device->oclass[NVDEV_ENGINE_CE0] = &gf100_ce0_oclass;
device->oclass[NVDEV_ENGINE_DISP   ] =  gf110_disp_oclass;
-   device->oclass[NVDEV_ENGINE_PM ] = gf100_pm_oclass;
+   device->oclass[NVDEV_ENGINE_PM ] = gf117_pm_oclass;
break;
case 0xd7:
device->cname = "GF117";
@@ -347,7 +347,7 @@ gf100_identify(struct nvkm_device *device)
device->oclass[NVDEV_ENGINE_MSPPP  ] = &gf100_msppp_oclass;
device->oclass[NVDEV_ENGINE_CE0] = &gf100_ce0_oclass;
device->oclass[NVDEV_ENGINE_DISP   ] =  gf110_disp_oclass;
-   device->oclass[NVDEV_ENGINE_PM ] = gf100_pm_oclass;
+   device->oclass[NVDEV_ENGINE_PM ] = gf117_pm_oclass;
break;
default:
nv_fatal(device, "unknown Fermi chipset\n");
diff --git a/drm/nouveau/nvkm/engine/pm/Kbuild 
b/drm/nouveau/nvkm/engine/pm/Kbuild
index cc01048..4fadf55 100644
--- a/drm/nouveau/nvkm/engine/pm/Kbuild
+++ b/drm/nouveau/nvkm/engine/pm/Kbuild
@@ -5,5 +5,7 @@ nvkm-y += nvkm/engine/pm/g84.o
 nvkm-y += nvkm/engine/pm/gt200.o
 nvkm-y += nvkm/engine/pm/gt215.o
 nvkm-y += nvkm/engine/pm/gf100.o
+nvkm-y += nvkm/engine/pm/gf108.o
+nvkm-y += nvkm/engine/pm/gf117.o
 nvkm-y += nvkm/engine/pm/gk104.o
 nvkm-y += nvkm/engine/pm/gk110.o
diff --git a/drm/nouveau/nvkm/engine/pm/gf100.c 
b/drm/nouveau/nvkm/engine/pm/gf100.c
index 64db47e..b40c218 100644
--- a/drm/nouveau/nvkm/engine/pm/gf100.c
+++ b/drm/nouveau/nvkm/engine/pm/gf100.c
@@ -23,18 +23,110 @@
  */
 #include "gf100.h"
 
+const struct nvkm_specsrc
+gf100_pmfb_sources[] = {
+   { 0x140028, (const struct nvkm_specmux[]) {
+   { 0x3fff, 0, "unk0" },
+   { 0x7, 16, "unk16" },
+   { 0x3, 24, "unk24" },
+   { 0x2, 29, "unk29" },
+   {}
+   }, "pmfb0_pm_unk28" },
+   {}
+};
+
+static const struct nvkm_specsrc
+gf100_l1_sources[] = {
+   { 0x5044a8, (const struct nvkm_specmux[]) {
+   { 0x3f, 0, "sel", true },
+   {}
+   }, "pgraph_gpc0_tpc0_l1_pm_mux" },
+   {}
+};
+
+static const struct nvkm_specsrc
+gf100_pbfb_sources[] = {
+   { 0x10f100, (const struct nvkm_specmux[]) {
+   { 0x1, 0, "unk0" },
+   { 0xf, 4,

Re: [Nouveau] [PATCH] fix a wrong use of a logical operator in drmmode_output_dpms()

2015-06-10 Thread Samuel Pitoiset

Pushed.

On 05/27/2015 01:23 PM, Samuel Pitoiset wrote:



On 05/21/2015 06:40 AM, Dave Airlie wrote:
On 21 May 2015 at 03:26, Samuel Pitoiset  
wrote:


On 05/20/2015 07:13 PM, Ilia Mirkin wrote:

This is obviously a bug, but one that has been there for some time.
Please figure out what this is guarding, and confirm that the feature
continues to work.


Sure, but do you have any ideas how to test this part of the DDX ?
It's the first time I play with it...


It's fine, the code just avoids going into the name checks if the type
isn't a enum,
it won't break anything actually fixing it.

The fix is

Reviewed-by: Dave Airlie 


Okay, thanks Dave.


___
Nouveau mailing list
Nouveau@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/nouveau


Re: [Nouveau] [PATCH RFC 05/20] pm: reorganize the nvif interface

2015-06-09 Thread Samuel Pitoiset



On 06/09/2015 12:02 AM, Ben Skeggs wrote:

On 8 June 2015 at 06:40, Samuel Pitoiset  wrote:

This commit introduces the NVIF_IOCTL_NEW_V0_PERFMON class which will be
used in order to query domains, signals and sources. This separates the
querying and the counting interface.

Hey Samuel,

I've merged patches 1-4 already, I've got some comments on this one,
but after they're solved I'm happy to merge up to (and including)
patch 18.  Patches 19/20, I need to think about some more.



Hey Ben,

Thanks for reviewing this series so quickly. :-)


Signed-off-by: Samuel Pitoiset 
---
  bin/nv_perfmon.c  | 12 ++--
  drm/nouveau/include/nvif/class.h  | 26 --
  drm/nouveau/include/nvif/ioctl.h  |  5 +++--
  drm/nouveau/nvkm/engine/pm/base.c | 38 --
  4 files changed, 57 insertions(+), 24 deletions(-)

diff --git a/bin/nv_perfmon.c b/bin/nv_perfmon.c
index a8c5838..30a3138 100644
--- a/bin/nv_perfmon.c
+++ b/bin/nv_perfmon.c
@@ -600,7 +600,7 @@ main(int argc, char **argv)
 const char *cfg = NULL;
 const char *dbg = "error";
 u64 dev = ~0ULL;
-   struct nvif_perfctr_query_v0 args = {};
+   struct nvif_perfmon_query_signal_v0 args = {};
 struct nvif_client *client;
 struct nvif_object object;
 int ret, c, k;
@@ -644,15 +644,14 @@ main(int argc, char **argv)
 }

 ret = nvif_object_init(nvif_object(device), NULL, 0xdeadbeef,
-  NVIF_IOCTL_NEW_V0_PERFCTR,
-  &(struct nvif_perfctr_v0) {
-  }, sizeof(struct nvif_perfctr_v0), &object);
+  NVIF_IOCTL_NEW_V0_PERFMON, NULL, 0, &object);
 assert(ret == 0);
 do {
 u32 prev_iter = args.iter;

 args.name[0] = '\0';
-   ret = nvif_mthd(&object, NVIF_PERFCTR_V0_QUERY, &args, 
sizeof(args));
+   ret = nvif_mthd(&object, NVIF_PERFMON_V0_QUERY_SIGNAL,
+   &args, sizeof(args));
 assert(ret == 0);

 if (prev_iter) {
@@ -663,7 +662,8 @@ main(int argc, char **argv)
 args.iter = prev_iter;
 strncpy(signals[nr_signals - 1], args.name,
 sizeof(args.name));
-   ret = nvif_mthd(&object, NVIF_PERFCTR_V0_QUERY, &args, 
sizeof(args));
+   ret = nvif_mthd(&object, NVIF_PERFMON_V0_QUERY_SIGNAL,
+   &args, sizeof(args));
 assert(ret == 0);
 }
 } while (args.iter != 0x);
diff --git a/drm/nouveau/include/nvif/class.h b/drm/nouveau/include/nvif/class.h
index 64f8b2f..11935a0 100644
--- a/drm/nouveau/include/nvif/class.h
+++ b/drm/nouveau/include/nvif/class.h
@@ -251,6 +251,20 @@ struct gf110_dma_v0 {
   * perfmon
   
**/

+#define NVIF_PERFMON_V0_QUERY_SIGNAL   0x00
+
+struct nvif_perfmon_query_signal_v0 {
+   __u8  version;
+   __u8  pad01[3];
+   __u32 iter;
+   char  name[64];
+};
+
+
+/***
+ * perfctr
+ 
**/
+
  struct nvif_perfctr_v0 {
 __u8  version;
 __u8  pad01[1];
@@ -259,16 +273,8 @@ struct nvif_perfctr_v0 {
 char  name[4][64];
  };

-#define NVIF_PERFCTR_V0_QUERY  0x00
-#define NVIF_PERFCTR_V0_SAMPLE 0x01
-#define NVIF_PERFCTR_V0_READ   0x02
-
-struct nvif_perfctr_query_v0 {
-   __u8  version;
-   __u8  pad01[3];
-   __u32 iter;
-   char  name[64];
-};
+#define NVIF_PERFCTR_V0_SAMPLE 0x00
+#define NVIF_PERFCTR_V0_READ   0x01

  struct nvif_perfctr_sample {
  };
diff --git a/drm/nouveau/include/nvif/ioctl.h b/drm/nouveau/include/nvif/ioctl.h
index 4cd8e32..517cd27 100644
--- a/drm/nouveau/include/nvif/ioctl.h
+++ b/drm/nouveau/include/nvif/ioctl.h
@@ -49,8 +49,9 @@ struct nvif_ioctl_new_v0 {
 __u64 token;
 __u32 handle;
  /* these class numbers are made up by us, and not nvidia-assigned */
-#define NVIF_IOCTL_NEW_V0_PERFCTR0x
-#define NVIF_IOCTL_NEW_V0_CONTROL0xfffe
+#define NVIF_IOCTL_NEW_V0_PERFMON0x
+#define NVIF_IOCTL_NEW_V0_PERFCTR0xfffe
+#define NVIF_IOCTL_NEW_V0_CONTROL  

[Nouveau] [PATCH RFC 15/20] pm: allow the userspace to schedule hardware counters

2015-06-07 Thread Samuel Pitoiset
This adds a new method NVIF_PERFCTR_V0_INIT which starts a batch of
hardware counters for sampling. This will allow the userspace to start
a monitoring session using the INIT method and to stop it with SAMPLE,
for example before and after a frame is rendered.

This commit temporarily breaks nv_perfmon but this is going to be fixed
with the upcoming patch.

Signed-off-by: Samuel Pitoiset 
---
 drm/nouveau/include/nvif/class.h  |  8 +++--
 drm/nouveau/nvkm/engine/pm/base.c | 64 +--
 drm/nouveau/nvkm/engine/pm/priv.h |  1 +
 3 files changed, 48 insertions(+), 25 deletions(-)

diff --git a/drm/nouveau/include/nvif/class.h b/drm/nouveau/include/nvif/class.h
index d85fb0d..528eac8 100644
--- a/drm/nouveau/include/nvif/class.h
+++ b/drm/nouveau/include/nvif/class.h
@@ -300,8 +300,12 @@ struct nvif_perfctr_v0 {
__u8  pad06[4];
 };
 
-#define NVIF_PERFCTR_V0_SAMPLE 0x00
-#define NVIF_PERFCTR_V0_READ   0x01
+#define NVIF_PERFCTR_V0_INIT   0x00
+#define NVIF_PERFCTR_V0_SAMPLE 0x01
+#define NVIF_PERFCTR_V0_READ   0x02
+
+struct nvif_perfctr_init {
+};
 
 struct nvif_perfctr_sample {
 };
diff --git a/drm/nouveau/nvkm/engine/pm/base.c 
b/drm/nouveau/nvkm/engine/pm/base.c
index ec02abf..5dbb3b4 100644
--- a/drm/nouveau/nvkm/engine/pm/base.c
+++ b/drm/nouveau/nvkm/engine/pm/base.c
@@ -307,13 +307,43 @@ nvkm_perfmon_ofuncs = {
  * Perfctr object classes
  
**/
 static int
+nvkm_perfctr_init(struct nvkm_object *object, void *data, u32 size)
+{
+   union {
+   struct nvif_perfctr_init none;
+   } *args = data;
+   struct nvkm_pm *ppm = (void *)object->engine;
+   struct nvkm_perfctr *ctr = (void *)object;
+   struct nvkm_perfdom *dom = ctr->dom;
+   int ret;
+
+   nv_ioctl(object, "perfctr init size %d\n", size);
+   if (nvif_unvers(args->none)) {
+   nv_ioctl(object, "perfctr init\n");
+   } else
+   return ret;
+
+   ctr->slot = ffs(dom->quad) - 1;
+   if (ctr->slot < 0) {
+   /* no free slots are available */
+   return -EINVAL;
+   }
+   dom->quad &= ~(QUAD_FREE << ctr->slot);
+   dom->func->init(ppm, dom, ctr);
+
+   /* start next batch of counters for sampling */
+   dom->func->next(ppm, dom);
+   return 0;
+}
+
+static int
 nvkm_perfctr_sample(struct nvkm_object *object, void *data, u32 size)
 {
union {
struct nvif_perfctr_sample none;
} *args = data;
struct nvkm_pm *ppm = (void *)object->engine;
-   struct nvkm_perfctr *ctr, *tmp;
+   struct nvkm_perfctr *ctr;
struct nvkm_perfdom *dom;
int ret;
 
@@ -328,32 +358,15 @@ nvkm_perfctr_sample(struct nvkm_object *object, void 
*data, u32 size)
/* sample previous batch of counters */
if (dom->quad != QUAD_MASK) {
dom->func->next(ppm, dom);
-   tmp = NULL;
-   while (!list_empty(&dom->list)) {
-   ctr = list_first_entry(&dom->list,
-  typeof(*ctr), head);
-   if (ctr->slot < 0) break;
-   if ( tmp && tmp == ctr) break;
-   if (!tmp) tmp = ctr;
+
+   /* read counter values */
+   list_for_each_entry(ctr, &dom->list, head) {
dom->func->read(ppm, dom, ctr);
-   ctr->slot  = -1;
-   list_move_tail(&ctr->head, &dom->list);
+   ctr->slot = -1;
}
-   }
-
-   dom->quad = QUAD_MASK;
 
-   /* setup next batch of counters for sampling */
-   list_for_each_entry(ctr, &dom->list, head) {
-   ctr->slot = ffs(dom->quad) - 1;
-   if (ctr->slot < 0)
-   break;
-   dom->quad &= ~(QUAD_FREE << ctr->slot);
-   dom->func->init(ppm, dom, ctr);
+   dom->quad = QUAD_MASK;
}
-
-   if (dom->quad != QUAD_MASK)
-   dom->func->next(ppm, dom);
}
 
return 0;
@@ -386,6 +399,8 @@ static int
 nvkm_perfctr_mthd(struct nvkm_object *object, u32 mthd, void *data, u32 size)
 {
switch (mthd) {
+   case

[Nouveau] [PATCH RFC 13/20] pm: allow to query the number of sources for a signal

2015-06-07 Thread Samuel Pitoiset
Signed-off-by: Samuel Pitoiset 
---
 drm/nouveau/include/nvif/class.h  |  3 ++-
 drm/nouveau/nvkm/engine/pm/base.c | 22 +++---
 2 files changed, 21 insertions(+), 4 deletions(-)

diff --git a/drm/nouveau/include/nvif/class.h b/drm/nouveau/include/nvif/class.h
index 9e4db3a..caae193 100644
--- a/drm/nouveau/include/nvif/class.h
+++ b/drm/nouveau/include/nvif/class.h
@@ -268,7 +268,8 @@ struct nvif_perfmon_query_signal_v0 {
__u8  domain;
__u16 iter;
__u8  signal;
-   __u8  pad04[3];
+   __u8  source_nr;
+   __u8  pad05[2];
char  name[64];
 };
 
diff --git a/drm/nouveau/nvkm/engine/pm/base.c 
b/drm/nouveau/nvkm/engine/pm/base.c
index dfafefd..a9c57a2 100644
--- a/drm/nouveau/nvkm/engine/pm/base.c
+++ b/drm/nouveau/nvkm/engine/pm/base.c
@@ -91,6 +91,18 @@ nvkm_perfsig_find(struct nvkm_pm *ppm, uint8_t di, uint8_t 
si,
return &dom->signal[si];
 }
 
+static u8
+nvkm_perfsig_count_perfsrc(struct nvkm_perfsig *sig)
+{
+   u8 source_nr = 0, i;
+
+   for (i = 0; i < ARRAY_SIZE(sig->source); i++) {
+   if (sig->source[i])
+   source_nr++;
+   }
+   return source_nr;
+}
+
 
/***
  * Perfmon object classes
  
**/
@@ -148,9 +160,9 @@ nvkm_perfmon_mthd_query_signal(struct nvkm_object *object, 
void *data, u32 size)
struct nvkm_device *device = nv_device(object);
struct nvkm_pm *ppm = (void *)object->engine;
struct nvkm_perfdom *dom;
+   struct nvkm_perfsig *sig;
const bool all = nvkm_boolopt(device->cfgopt, "NvPmShowAll", false);
const bool raw = nvkm_boolopt(device->cfgopt, "NvPmUnnamed", all);
-   const char *name;
int ret, si;
 
nv_ioctl(object, "perfmon query signal size %d\n", size);
@@ -167,13 +179,17 @@ nvkm_perfmon_mthd_query_signal(struct nvkm_object 
*object, void *data, u32 size)
return -EINVAL;
 
if (si >= 0) {
-   if (raw || !(name = dom->signal[si].name)) {
+   sig = &dom->signal[si];
+   if (raw || !sig->name) {
snprintf(args->v0.name, sizeof(args->v0.name),
 "/%s/%02x", dom->name, si);
} else {
-   strncpy(args->v0.name, name, sizeof(args->v0.name));
+   strncpy(args->v0.name, sig->name,
+   sizeof(args->v0.name));
}
+
args->v0.signal = si;
+   args->v0.source_nr = nvkm_perfsig_count_perfsrc(sig);
}
 
while (++si < dom->signal_nr) {
-- 
2.4.2

___
Nouveau mailing list
Nouveau@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/nouveau


[Nouveau] [PATCH RFC 14/20] pm: implement NVIF_PERFMON_V0_QUERY_SOURCE method

2015-06-07 Thread Samuel Pitoiset
This allows to query the ID, the mask and the user-readable name of
sources for each signal.

Signed-off-by: Samuel Pitoiset 
---
 drm/nouveau/include/nvif/class.h  | 12 ++
 drm/nouveau/nvkm/engine/pm/base.c | 77 +++
 2 files changed, 89 insertions(+)

diff --git a/drm/nouveau/include/nvif/class.h b/drm/nouveau/include/nvif/class.h
index caae193..d85fb0d 100644
--- a/drm/nouveau/include/nvif/class.h
+++ b/drm/nouveau/include/nvif/class.h
@@ -253,6 +253,7 @@ struct gf110_dma_v0 {
 
 #define NVIF_PERFMON_V0_QUERY_DOMAIN   0x00
 #define NVIF_PERFMON_V0_QUERY_SIGNAL   0x01
+#define NVIF_PERFMON_V0_QUERY_SOURCE   0x02
 
 struct nvif_perfmon_query_domain_v0 {
__u8  version;
@@ -273,6 +274,17 @@ struct nvif_perfmon_query_signal_v0 {
char  name[64];
 };
 
+struct nvif_perfmon_query_source_v0 {
+   __u8  version;
+   __u8  domain;
+   __u8  signal;
+   __u8  iter;
+   __u8  pad04[4];
+   __u32 source;
+   __u32 mask;
+   char  name[64];
+};
+
 
 
/***
  * perfctr
diff --git a/drm/nouveau/nvkm/engine/pm/base.c 
b/drm/nouveau/nvkm/engine/pm/base.c
index a9c57a2..ec02abf 100644
--- a/drm/nouveau/nvkm/engine/pm/base.c
+++ b/drm/nouveau/nvkm/engine/pm/base.c
@@ -103,6 +103,31 @@ nvkm_perfsig_count_perfsrc(struct nvkm_perfsig *sig)
return source_nr;
 }
 
+static struct nvkm_perfsrc *
+nvkm_perfsrc_find(struct nvkm_pm *ppm, struct nvkm_perfsig *sig, int si)
+{
+   struct nvkm_perfsrc *src;
+   bool found = false;
+   int tmp = 1; /* Sources ID start from 1 */
+   u8 i;
+
+   for (i = 0; i < ARRAY_SIZE(sig->source) && sig->source[i]; i++) {
+   if (sig->source[i] == si) {
+   found = true;
+   break;
+   }
+   }
+
+   if (found) {
+   list_for_each_entry(src, &ppm->sources, head) {
+   if (tmp++ == si)
+   return src;
+   }
+   }
+
+   return NULL;
+}
+
 
/***
  * Perfmon object classes
  
**/
@@ -204,6 +229,56 @@ nvkm_perfmon_mthd_query_signal(struct nvkm_object *object, 
void *data, u32 size)
 }
 
 static int
+nvkm_perfmon_mthd_query_source(struct nvkm_object *object, void *data, u32 
size)
+{
+   union {
+   struct nvif_perfmon_query_source_v0 v0;
+   } *args = data;
+   struct nvkm_pm *ppm = (void *)object->engine;
+   struct nvkm_perfdom *dom = NULL;
+   struct nvkm_perfsig *sig;
+   struct nvkm_perfsrc *src;
+   u8 source_nr = 0;
+   int si, ret;
+
+   nv_ioctl(object, "perfmon query source size %d\n", size);
+   if (nvif_unpack(args->v0, 0, 0, false)) {
+   nv_ioctl(object,
+"perfmon source vers %d dom %d sig %02x iter %02x\n",
+args->v0.version, args->v0.domain, args->v0.signal,
+args->v0.iter);
+   si = (args->v0.iter & 0xff) - 1;
+   } else
+   return ret;
+
+   sig = nvkm_perfsig_find(ppm, args->v0.domain, args->v0.signal, &dom);
+   if (!sig)
+   return -EINVAL;
+
+   source_nr = nvkm_perfsig_count_perfsrc(sig);
+   if (si >= (int)source_nr)
+   return -EINVAL;
+
+   if (si >= 0) {
+   src = nvkm_perfsrc_find(ppm, sig, sig->source[si]);
+   if (!src)
+   return -EINVAL;
+
+   args->v0.source = sig->source[si];
+   args->v0.mask   = src->mask;
+   strncpy(args->v0.name, src->name, sizeof(args->v0.name));
+   }
+
+   if (++si < source_nr) {
+   args->v0.iter = ++si;
+   return 0;
+   }
+
+   args->v0.iter = 0xff;
+   return 0;
+}
+
+static int
 nvkm_perfmon_mthd(struct nvkm_object *object, u32 mthd, void *data, u32 size)
 {
switch (mthd) {
@@ -211,6 +286,8 @@ nvkm_perfmon_mthd(struct nvkm_object *object, u32 mthd, 
void *data, u32 size)
return nvkm_perfmon_mthd_query_domain(object, data, size);
case NVIF_PERFMON_V0_QUERY_SIGNAL:
return nvkm_perfmon_mthd_query_signal(object, data, size);
+   case NVIF_PERFMON_V0_QUERY_SOURCE:
+   return nvkm_perfmon_mthd_query_source(object, data, size);
default:
break;
}
-- 
2.4.2

___
Nouveau mailing list
Nouveau@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/nouveau


[Nouveau] [PATCH RFC 09/20] pm: change signal iter to u16

2015-06-07 Thread Samuel Pitoiset
16 bits is large enough to store the maximum number of signals available
for one domain (i.e. 256).

Signed-off-by: Samuel Pitoiset 
---
 bin/nv_perfmon.c  |  4 ++--
 drm/nouveau/include/nvif/class.h  |  7 ---
 drm/nouveau/nvkm/engine/pm/base.c | 10 +-
 drm/nouveau/nvkm/engine/pm/priv.h |  2 +-
 4 files changed, 12 insertions(+), 11 deletions(-)

diff --git a/bin/nv_perfmon.c b/bin/nv_perfmon.c
index 958520e..043d864 100644
--- a/bin/nv_perfmon.c
+++ b/bin/nv_perfmon.c
@@ -289,7 +289,7 @@ ui_perfmon_query_signals(struct nvif_object *perfmon,
 
args.domain = dom->id;
do {
-   u32 prev_iter = args.iter;
+   u16 prev_iter = args.iter;
 
args.name[0] = '\0';
ret = nvif_mthd(perfmon, NVIF_PERFMON_V0_QUERY_SIGNAL,
@@ -308,7 +308,7 @@ ui_perfmon_query_signals(struct nvif_object *perfmon,
&args, sizeof(args));
assert(ret == 0);
}
-   } while (args.iter != 0x);
+   } while (args.iter != 0x);
 }
 
 static void
diff --git a/drm/nouveau/include/nvif/class.h b/drm/nouveau/include/nvif/class.h
index cf2af89..871247c 100644
--- a/drm/nouveau/include/nvif/class.h
+++ b/drm/nouveau/include/nvif/class.h
@@ -259,14 +259,15 @@ struct nvif_perfmon_query_domain_v0 {
__u8  id;
__u8  counter_nr;
__u8  iter;
-   __u32 signal_nr;
+   __u16 signal_nr;
+   __u8  pad05[2];
 };
 
 struct nvif_perfmon_query_signal_v0 {
__u8  version;
__u8  domain;
-   __u8  pad02[2];
-   __u32 iter;
+   __u16 iter;
+   __u8  pad03[4];
char  name[64];
 };
 
diff --git a/drm/nouveau/nvkm/engine/pm/base.c 
b/drm/nouveau/nvkm/engine/pm/base.c
index d61beff..fab0598 100644
--- a/drm/nouveau/nvkm/engine/pm/base.c
+++ b/drm/nouveau/nvkm/engine/pm/base.c
@@ -45,10 +45,10 @@ nvkm_pm_count_perfdom(struct nvkm_pm *ppm)
return domain_nr;
 }
 
-static u32
+static u16
 nvkm_perfdom_count_perfsig(struct nvkm_perfdom *dom)
 {
-   u32 signal_nr = 0;
+   u16 signal_nr = 0;
int i;
 
if (dom) {
@@ -183,9 +183,9 @@ nvkm_perfmon_mthd_query_signal(struct nvkm_object *object, 
void *data, u32 size)
nv_ioctl(object, "perfmon query signal size %d\n", size);
if (nvif_unpack(args->v0, 0, 0, false)) {
nv_ioctl(object,
-"perfmon query signal vers %d dom %d iter %08x\n",
+"perfmon query signal vers %d dom %d iter %04x\n",
 args->v0.version, args->v0.domain, args->v0.iter);
-   si = (args->v0.iter & 0x) - 1;
+   si = (args->v0.iter & 0x) - 1;
} else
return ret;
 
@@ -209,7 +209,7 @@ nvkm_perfmon_mthd_query_signal(struct nvkm_object *object, 
void *data, u32 size)
}
}
 
-   args->v0.iter = 0x;
+   args->v0.iter = 0x;
return 0;
 }
 
diff --git a/drm/nouveau/nvkm/engine/pm/priv.h 
b/drm/nouveau/nvkm/engine/pm/priv.h
index 06a6e60..71667fc 100644
--- a/drm/nouveau/nvkm/engine/pm/priv.h
+++ b/drm/nouveau/nvkm/engine/pm/priv.h
@@ -44,7 +44,7 @@ struct nvkm_perfdom {
char name[32];
u32 addr;
u8  quad;
-   u32 signal_nr;
+   u16 signal_nr;
struct nvkm_perfsig signal[];
 };
 
-- 
2.4.2

___
Nouveau mailing list
Nouveau@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/nouveau


[Nouveau] [PATCH RFC 17/20] pm: allow the userspace to configure sources

2015-06-07 Thread Samuel Pitoiset
Signed-off-by: Samuel Pitoiset 
---
 drm/nouveau/include/nvif/class.h  |   1 +
 drm/nouveau/nvkm/engine/pm/base.c | 102 ++
 drm/nouveau/nvkm/engine/pm/priv.h |   2 +
 3 files changed, 95 insertions(+), 10 deletions(-)

diff --git a/drm/nouveau/include/nvif/class.h b/drm/nouveau/include/nvif/class.h
index 1a76a7f..3b7f49f 100644
--- a/drm/nouveau/include/nvif/class.h
+++ b/drm/nouveau/include/nvif/class.h
@@ -297,6 +297,7 @@ struct nvif_perfdom_v0 {
__u8  pad03[1];
struct {
__u8  signal[4];
+   __u64 source[4][8];
__u16 logic_op;
} ctr[4];
 };
diff --git a/drm/nouveau/nvkm/engine/pm/base.c 
b/drm/nouveau/nvkm/engine/pm/base.c
index 8960bf4..a4bb6fe 100644
--- a/drm/nouveau/nvkm/engine/pm/base.c
+++ b/drm/nouveau/nvkm/engine/pm/base.c
@@ -125,6 +125,66 @@ nvkm_perfsrc_find(struct nvkm_pm *ppm, struct nvkm_perfsig 
*sig, int si)
return NULL;
 }
 
+static int
+nvkm_perfsrc_enable(struct nvkm_pm *ppm, struct nvkm_perfctr *ctr)
+{
+   struct nvkm_perfdom *dom = NULL;
+   struct nvkm_perfsig *sig;
+   struct nvkm_perfsrc *src;
+   u32 mask, value;
+   int i, j;
+
+   for (i = 0; i < 4 && ctr->signal[i]; i++) {
+   for (j = 0; j < 8 && ctr->source[i][j]; j++) {
+   sig = nvkm_perfsig_find(ppm, ctr->domain,
+   ctr->signal[i], &dom);
+   if (!sig)
+   return -EINVAL;
+
+   src = nvkm_perfsrc_find(ppm, sig, ctr->source[i][j]);
+   if (!src)
+   return -EINVAL;
+
+   /* set enable bit if needed */
+   mask = value = 0x;
+   if (src->enable)
+   mask = value = 0x8000;
+   mask  |= (src->mask << src->shift);
+   value |= ((ctr->source[i][j] >> 32) << src->shift);
+
+   /* enable the source */
+   nv_mask(ppm, src->addr, mask, value);
+   }
+   }
+   return 0;
+}
+
+static int
+nvkm_perfsrc_disable(struct nvkm_pm *ppm, struct nvkm_perfctr *ctr)
+{
+   struct nvkm_perfdom *dom = NULL;
+   struct nvkm_perfsig *sig;
+   struct nvkm_perfsrc *src;
+   int i, j;
+
+   for (i = 0; i < 4 && ctr->signal[i]; i++) {
+   for (j = 0; j < 8 && ctr->source[i][j]; j++) {
+   sig = nvkm_perfsig_find(ppm, ctr->domain,
+   ctr->signal[i], &dom);
+   if (!sig)
+   return -EINVAL;
+
+   src = nvkm_perfsrc_find(ppm, sig, ctr->source[i][j]);
+   if (!src)
+   return -EINVAL;
+
+   /* disable the source */
+   nv_mask(ppm, src->addr, src->mask << src->shift, 0);
+   }
+   }
+   return 0;
+}
+
 
/***
  * Perfmon object classes
  
**/
@@ -319,10 +379,15 @@ nvkm_perfdom_init(struct nvkm_object *object, void *data, 
u32 size)
} else
return ret;
 
-   for (i = 0; i < 4; i++)
-   if (dom->ctr[i])
+   for (i = 0; i < 4; i++) {
+   if (dom->ctr[i]) {
dom->func->init(ppm, dom, dom->ctr[i]);
 
+   /* enable sources */
+   nvkm_perfsrc_enable(ppm, dom->ctr[i]);
+   }
+   }
+
/* start next batch of counters for sampling */
dom->func->next(ppm, dom);
return 0;
@@ -402,13 +467,17 @@ nvkm_perfdom_mthd(struct nvkm_object *object, u32 mthd, 
void *data, u32 size)
 static void
 nvkm_perfdom_dtor(struct nvkm_object *object)
 {
+   struct nvkm_pm *ppm = (void *)object->engine;
struct nvkm_perfdom *dom = (void *)object;
int i;
 
for (i = 0; i < 4; i++) {
struct nvkm_perfctr *ctr = dom->ctr[i];
-   if (ctr && ctr->head.next)
-   list_del(&ctr->head);
+   if (ctr) {
+   nvkm_perfsrc_disable(ppm, ctr);
+   if (ctr->head.next)
+   list_del(&ctr->head);
+   }
kfree(ctr);
}
nvkm_object_destroy(&dom->base);
@@ -416,11 +485,11 @@ nvkm_perfdom_dtor(struct nvkm_object *object)
 
 static int
 nvkm_perfctr_new(struct nvkm_perfdom *dom, int slot,
-struct nvkm_perfsig *si

[Nouveau] [PATCH RFC 16/20] pm: allow to configure domains instead of simple counters

2015-06-07 Thread Samuel Pitoiset
Configuring counters from the userspace require the kernel to handle some
logic related to performance counters. Basically, it has to find a free
slot to assign a counter, to handle extra counting modes like B4/B6 and it
must return and error when it can't configure a counter.

In my opinion, the kernel should not handle all of that logic but it
should only write the configuration sent by the userspace without
checking anything. In other words, it should overwrite the configuration
even if it's already counting and do not return any errors.

This patch allows the userspace to configure a domain instead of
separate counters. This has the advantage to move all of the logic to
the userspace.

Signed-off-by: Samuel Pitoiset 
---
 bin/nv_perfmon.c   | 193 ++
 drm/nouveau/include/nvif/class.h   |  30 +++---
 drm/nouveau/include/nvif/ioctl.h   |   2 +-
 drm/nouveau/nvkm/engine/pm/base.c  | 208 +
 drm/nouveau/nvkm/engine/pm/gf100.c |  10 +-
 drm/nouveau/nvkm/engine/pm/nv40.c  |  10 +-
 drm/nouveau/nvkm/engine/pm/priv.h  |  10 +-
 7 files changed, 293 insertions(+), 170 deletions(-)

diff --git a/bin/nv_perfmon.c b/bin/nv_perfmon.c
index 50c..47b2fef 100644
--- a/bin/nv_perfmon.c
+++ b/bin/nv_perfmon.c
@@ -248,7 +248,8 @@ ui_menu_win = {
 
 struct ui_perfmon_dom {
struct list_head head;
-   struct list_head list;
+   struct list_head signals;
+   struct list_head perfdoms;
u8 id;
 };
 
@@ -260,22 +261,27 @@ struct ui_perfmon_sig {
 
 struct ui_main {
struct list_head head;
-   u32 handle;
-   struct nvif_object object;
-   const char *name;
+   struct ui_perfmon_sig *sig;
u32 clk;
u32 ctr;
u64 incr;
 };
 
+struct ui_perfdom {
+   struct nvif_object object;
+   struct list_head head;
+   struct ui_main *ctr[4];
+   u32 handle;
+};
+
 static struct list_head ui_main_list = LIST_HEAD_INIT(ui_main_list);
 static struct list_head ui_doms_list = LIST_HEAD_INIT(ui_doms_list);
+static struct list_head ui_perfdom_list = LIST_HEAD_INIT(ui_perfdom_list);
 static u32 ui_main_handle = 0xc000;
 
 static void
 ui_main_remove(struct ui_main *item)
 {
-   nvif_object_fini(&item->object);
list_del(&item->head);
free(item);
 }
@@ -303,7 +309,7 @@ ui_perfmon_query_signals(struct nvif_object *perfmon,
sig->signal = args.signal;
sig->name = malloc(sizeof(args.name));
strncpy(sig->name, args.name, sizeof(args.name));
-   list_add_tail(&sig->head, &dom->list);
+   list_add_tail(&sig->head, &dom->signals);
 
args.iter = prev_iter;
ret = nvif_mthd(perfmon, NVIF_PERFMON_V0_QUERY_SIGNAL,
@@ -331,7 +337,8 @@ ui_perfmon_query_domains(struct nvif_object *perfmon)
if (prev_iter) {
dom = calloc(1, sizeof(*dom));
dom->id = args.id;
-   INIT_LIST_HEAD(&dom->list);
+   INIT_LIST_HEAD(&dom->signals);
+   INIT_LIST_HEAD(&dom->perfdoms);
list_add_tail(&dom->head, &ui_doms_list);
 
args.iter = prev_iter;
@@ -346,6 +353,49 @@ ui_perfmon_query_domains(struct nvif_object *perfmon)
 }
 
 static void
+ui_perfdom_init(struct ui_perfdom *dom)
+{
+   struct nvif_perfdom_init args = {};
+   int ret;
+
+   ret = nvif_mthd(&dom->object, NVIF_PERFDOM_V0_INIT,
+   &args, sizeof(args));
+   assert(ret == 0);
+}
+
+static void
+ui_perfdom_sample(struct ui_perfdom *dom)
+{
+   struct nvif_perfdom_sample args = {};
+   int ret;
+
+   ret = nvif_mthd(&dom->object, NVIF_PERFDOM_V0_SAMPLE,
+   &args, sizeof(args));
+   assert(ret == 0);
+}
+
+static void
+ui_perfdom_read(struct ui_perfdom *dom)
+{
+   struct nvif_perfdom_read_v0 args = {};
+   int ret, i;
+
+   ret = nvif_mthd(&dom->object, NVIF_PERFDOM_V0_READ,
+   &args, sizeof(args));
+   assert(ret == 0 || ret == -EAGAIN);
+
+   if (ret == 0) {
+   for (i = 0; i < 4; i++) {
+   if (!dom->ctr[i])
+   continue;
+   dom->ctr[i]->ctr   = args.ctr[i];
+   dom->ctr[i]->incr += args.ctr[i];
+   dom->ctr[i]->clk   = args.clk;
+   }
+   }
+}
+
+static void
 ui_perfmon_init(void)
 {
struct nvif_object perfmon;
@@ -362,17 +412,37 @@ ui_perfmon_init(void)
 }
 
 static void
+ui_perfmon_free_signals(struct ui_perfmon_dom *dom)
+{
+   struct ui_perfmon_sig *sig, *next;
+
+   l

[Nouveau] [PATCH RFC 19/20] sw/nv50: add some private functions to factorize code

2015-06-07 Thread Samuel Pitoiset
These functions will be also used by the interface for controlling
performance counters.

Signed-off-by: Samuel Pitoiset 
---
 drm/nouveau/nvkm/engine/sw/nv50.c | 56 ++-
 1 file changed, 38 insertions(+), 18 deletions(-)

diff --git a/drm/nouveau/nvkm/engine/sw/nv50.c 
b/drm/nouveau/nvkm/engine/sw/nv50.c
index 401fcd7..b7c0227 100644
--- a/drm/nouveau/nvkm/engine/sw/nv50.c
+++ b/drm/nouveau/nvkm/engine/sw/nv50.c
@@ -36,27 +36,58 @@
  
**/
 
 static int
-nv50_sw_mthd_dma_vblsem(struct nvkm_object *object, u32 mthd,
-   void *args, u32 size)
+nv50_priv_ctxdma_get(struct nv50_sw_chan *chan, u32 name, u32 *ctxdma)
 {
-   struct nv50_sw_chan *chan = (void *)nv_engctx(object->parent);
struct nvkm_fifo_chan *fifo = (void *)nv_object(chan)->parent;
struct nvkm_handle *handle;
int ret = -EINVAL;
 
-   handle = nvkm_namedb_get(nv_namedb(fifo), *(u32 *)args);
+   handle = nvkm_namedb_get(nv_namedb(fifo), name);
if (!handle)
return -ENOENT;
 
if (nv_iclass(handle->object, NV_GPUOBJ_CLASS)) {
struct nvkm_gpuobj *gpuobj = nv_gpuobj(handle->object);
-   chan->vblank.ctxdma = gpuobj->node->offset >> 4;
+   *ctxdma = gpuobj->node->offset >> 4;
ret = 0;
}
nvkm_namedb_put(handle);
return ret;
 }
 
+static void
+nv50_priv_ctxdma_flush(struct nv50_sw_chan *chan, u32 channel, u32 ctxdma)
+{
+   struct nv50_sw_priv *priv = (void *)nv_object(chan)->engine;
+   struct nvkm_bar *bar = nvkm_bar(priv);
+
+   nv_wr32(priv, 0x001704, channel);
+   nv_wr32(priv, 0x001710, 0x8000 | ctxdma);
+   bar->flush(bar);
+}
+
+static void
+nv50_priv_ctxdma_wr32(struct nv50_sw_chan *chan, u64 offset, u32 value)
+{
+   struct nv50_sw_priv *priv = (void *)nv_object(chan)->engine;
+
+   if (nv_device(priv)->chipset == 0x50) {
+   nv_wr32(priv, 0x001570, offset);
+   nv_wr32(priv, 0x001574, value);
+   } else {
+   nv_wr32(priv, 0x060010, offset);
+   nv_wr32(priv, 0x060014, value);
+   }
+}
+
+static int
+nv50_sw_mthd_dma_vblsem(struct nvkm_object *object, u32 mthd,
+   void *args, u32 size)
+{
+   struct nv50_sw_chan *chan = (void *)nv_engctx(object->parent);
+   return nv50_priv_ctxdma_get(chan, *(u32 *)args, &chan->vblank.ctxdma);
+}
+
 static int
 nv50_sw_mthd_vblsem_offset(struct nvkm_object *object, u32 mthd,
   void *args, u32 size)
@@ -122,20 +153,9 @@ nv50_sw_vblsem_release(struct nvkm_notify *notify)
 {
struct nv50_sw_chan *chan =
container_of(notify, typeof(*chan), 
vblank.notify[notify->index]);
-   struct nv50_sw_priv *priv = (void *)nv_object(chan)->engine;
-   struct nvkm_bar *bar = nvkm_bar(priv);
-
-   nv_wr32(priv, 0x001704, chan->vblank.channel);
-   nv_wr32(priv, 0x001710, 0x8000 | chan->vblank.ctxdma);
-   bar->flush(bar);
 
-   if (nv_device(priv)->chipset == 0x50) {
-   nv_wr32(priv, 0x001570, chan->vblank.offset);
-   nv_wr32(priv, 0x001574, chan->vblank.value);
-   } else {
-   nv_wr32(priv, 0x060010, chan->vblank.offset);
-   nv_wr32(priv, 0x060014, chan->vblank.value);
-   }
+   nv50_priv_ctxdma_flush(chan, chan->vblank.channel, chan->vblank.ctxdma);
+   nv50_priv_ctxdma_wr32(chan, chan->vblank.offset, chan->vblank.value);
 
return NVKM_NOTIFY_DROP;
 }
-- 
2.4.2

___
Nouveau mailing list
Nouveau@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/nouveau


[Nouveau] [PATCH RFC 20/20] sw/nv50: add and interface for controlling performance counters

2015-06-07 Thread Samuel Pitoiset
This software methods interface will allow the userspace to tie
monitoring of performance counters to the command stream.

Signed-off-by: Samuel Pitoiset 
---
 drm/nouveau/nvkm/engine/sw/nv50.c | 160 ++
 drm/nouveau/nvkm/engine/sw/nv50.h |   6 ++
 2 files changed, 166 insertions(+)

diff --git a/drm/nouveau/nvkm/engine/sw/nv50.c 
b/drm/nouveau/nvkm/engine/sw/nv50.c
index b7c0227..b5f8263 100644
--- a/drm/nouveau/nvkm/engine/sw/nv50.c
+++ b/drm/nouveau/nvkm/engine/sw/nv50.c
@@ -29,7 +29,9 @@
 #include 
 #include 
 
+#include 
 #include 
+#include 
 
 
/***
  * software object classes
@@ -80,6 +82,14 @@ nv50_priv_ctxdma_wr32(struct nv50_sw_chan *chan, u64 offset, 
u32 value)
}
 }
 
+static u64
+nv50_priv_pm_get_offset(struct nv50_sw_chan *chan, u32 sequence)
+{
+   u32 max_queries = chan->pm.max_queries;
+   u32 ring_size = chan->pm.ring_size;
+   return (1 + (sequence % ring_size) * max_queries * 3) * 4;
+}
+
 static int
 nv50_sw_mthd_dma_vblsem(struct nvkm_object *object, u32 mthd,
void *args, u32 size)
@@ -128,13 +138,163 @@ nv50_sw_mthd_flip(struct nvkm_object *object, u32 mthd, 
void *args, u32 size)
return -EINVAL;
 }
 
+static int
+nv50_sw_mthd_dma_pm(struct nvkm_object *object, u32 mthd,
+   void *args, u32 size)
+{
+   struct nv50_sw_chan *chan = (void *)nv_engctx(object->parent);
+   return nv50_priv_ctxdma_get(chan, *(u32 *)args, &chan->pm.ctxdma);
+}
+
+static int
+nv50_sw_mthd_pm_ring_size(struct nvkm_object *object, u32 mthd,
+ void *args, u32 size)
+{
+   struct nv50_sw_chan *chan = (void *)nv_engctx(object->parent);
+   chan->pm.ring_size = *(u32 *)args;
+   return 0;
+}
+
+static int
+nv50_sw_mthd_pm_max_queries(struct nvkm_object *object, u32 mthd,
+   void *args, u32 size)
+{
+   struct nv50_sw_chan *chan = (void *)nv_engctx(object->parent);
+   chan->pm.max_queries = *(u32 *)args;
+   return 0;
+}
+
+static int
+nv50_sw_mthd_pm_mthd_init(struct nvkm_object *object, u32 mthd,
+ void *args, u32 size)
+{
+   struct nv50_sw_chan *chan = (void *)nv_engctx(object->parent);
+   struct nvkm_fifo_chan *fifo = (void *)nv_object(chan)->parent;
+   struct nvkm_handle *handle;
+   struct nvkm_object *namedb;
+   int ret = -EINVAL;
+
+   namedb = nv_object(fifo)->parent;
+   while (!nv_iclass(namedb, NV_NAMEDB_CLASS))
+   namedb = namedb->parent;
+
+   handle = nvkm_namedb_get(nv_namedb(namedb), *(u32 *)args);
+   if (!handle)
+   return -ENOENT;
+
+   if (nv_iclass(handle->object, NVIF_IOCTL_NEW_V0_PERFMON)) {
+   struct nvkm_object *object = handle->object;
+   struct nvkm_ofuncs *ofuncs = object->oclass->ofuncs;
+   struct nvif_perfdom_init args = {};
+
+   ret = ofuncs->mthd(object, NVIF_PERFDOM_V0_INIT,
+  &args, sizeof(args));
+   }
+   nvkm_namedb_put(handle);
+   return ret;
+}
+
+static int
+nv50_sw_mthd_pm_mthd_sample(struct nvkm_object *object, u32 mthd,
+   void *args, u32 size)
+{
+   struct nv50_sw_chan *chan = (void *)nv_engctx(object->parent);
+   struct nvkm_fifo_chan *fifo = (void *)nv_object(chan)->parent;
+   struct nvkm_handle *handle;
+   struct nvkm_object *namedb;
+   int ret = -EINVAL;
+
+   namedb = nv_object(fifo)->parent;
+   while (!nv_iclass(namedb, NV_NAMEDB_CLASS))
+   namedb = namedb->parent;
+
+   handle = nvkm_namedb_get(nv_namedb(namedb), *(u32 *)args);
+   if (!handle)
+   return -ENOENT;
+
+   if (nv_iclass(handle->object, NVIF_IOCTL_NEW_V0_PERFMON)) {
+   struct nvkm_object *object = handle->object;
+   struct nvkm_ofuncs *ofuncs = object->oclass->ofuncs;
+   struct nvif_perfdom_sample args = {};
+
+   ret = ofuncs->mthd(object, NVIF_PERFDOM_V0_SAMPLE,
+  &args, sizeof(args));
+   }
+   nvkm_namedb_put(handle);
+   return ret;
+}
+
+static int
+nv50_sw_mthd_pm_mthd_read(struct nvkm_object *object, u32 mthd,
+ void *args, u32 size)
+{
+   struct nv50_sw_chan *chan = (void *)nv_engctx(object->parent);
+   struct nvkm_fifo_chan *fifo = (void *)nv_object(chan)->parent;
+   struct nvkm_handle *handle;
+   struct nvkm_object *namedb;
+   u32 seq = *(u32 *)args;
+   int ret = -ENOENT;
+   u64 offset;
+   int i;
+
+   nv50_priv_ctxdma_flush(chan, chan->vblank.channel, chan->pm.ctxdma);
+   offset = nv50_priv_pm_get_offset(chan, seq);
+
+   namedb = nv_object(fifo)->parent;
+   while (!nv

[Nouveau] [PATCH RFC 18/20] pm/nv50: add compute and graphics signals/sources

2015-06-07 Thread Samuel Pitoiset
These signals and sources have been reverse engineered from NVIDIA
PerfKit (Windows) and CUPTI (Linux), they will be used to build complex
hardware events from the userspace.

This commit also adds a new class for GT200.

Signed-off-by: Samuel Pitoiset 
---
 drm/nouveau/include/nvkm/engine/pm.h  |   1 +
 drm/nouveau/nvkm/engine/device/nv50.c |   2 +-
 drm/nouveau/nvkm/engine/pm/Kbuild |   1 +
 drm/nouveau/nvkm/engine/pm/g84.c  | 101 -
 drm/nouveau/nvkm/engine/pm/gt200.c| 163 ++
 drm/nouveau/nvkm/engine/pm/gt215.c|  84 +-
 drm/nouveau/nvkm/engine/pm/nv50.c | 136 ++--
 drm/nouveau/nvkm/engine/pm/priv.h |   8 ++
 8 files changed, 485 insertions(+), 11 deletions(-)
 create mode 100644 drm/nouveau/nvkm/engine/pm/gt200.c

diff --git a/drm/nouveau/include/nvkm/engine/pm.h 
b/drm/nouveau/include/nvkm/engine/pm.h
index 130b545..82f1c7f 100644
--- a/drm/nouveau/include/nvkm/engine/pm.h
+++ b/drm/nouveau/include/nvkm/engine/pm.h
@@ -24,6 +24,7 @@ nvkm_pm(void *obj)
 extern struct nvkm_oclass *nv40_pm_oclass;
 extern struct nvkm_oclass *nv50_pm_oclass;
 extern struct nvkm_oclass *g84_pm_oclass;
+extern struct nvkm_oclass *gt200_pm_oclass;
 extern struct nvkm_oclass *gt215_pm_oclass;
 extern struct nvkm_oclass gf100_pm_oclass;
 extern struct nvkm_oclass gk104_pm_oclass;
diff --git a/drm/nouveau/nvkm/engine/device/nv50.c 
b/drm/nouveau/nvkm/engine/device/nv50.c
index 249b844..a2627ec 100644
--- a/drm/nouveau/nvkm/engine/device/nv50.c
+++ b/drm/nouveau/nvkm/engine/device/nv50.c
@@ -288,7 +288,7 @@ nv50_identify(struct nvkm_device *device)
device->oclass[NVDEV_ENGINE_CIPHER ] = &g84_cipher_oclass;
device->oclass[NVDEV_ENGINE_BSP] = &g84_bsp_oclass;
device->oclass[NVDEV_ENGINE_DISP   ] =  gt200_disp_oclass;
-   device->oclass[NVDEV_ENGINE_PM ] =  g84_pm_oclass;
+   device->oclass[NVDEV_ENGINE_PM ] =  gt200_pm_oclass;
break;
case 0xaa:
device->cname = "MCP77/MCP78";
diff --git a/drm/nouveau/nvkm/engine/pm/Kbuild 
b/drm/nouveau/nvkm/engine/pm/Kbuild
index c5ee8d5..cc01048 100644
--- a/drm/nouveau/nvkm/engine/pm/Kbuild
+++ b/drm/nouveau/nvkm/engine/pm/Kbuild
@@ -2,6 +2,7 @@ nvkm-y += nvkm/engine/pm/base.o
 nvkm-y += nvkm/engine/pm/nv40.o
 nvkm-y += nvkm/engine/pm/nv50.o
 nvkm-y += nvkm/engine/pm/g84.o
+nvkm-y += nvkm/engine/pm/gt200.o
 nvkm-y += nvkm/engine/pm/gt215.o
 nvkm-y += nvkm/engine/pm/gf100.o
 nvkm-y += nvkm/engine/pm/gk104.o
diff --git a/drm/nouveau/nvkm/engine/pm/g84.c b/drm/nouveau/nvkm/engine/pm/g84.c
index d54c670..dda539c 100644
--- a/drm/nouveau/nvkm/engine/pm/g84.c
+++ b/drm/nouveau/nvkm/engine/pm/g84.c
@@ -23,15 +23,112 @@
  */
 #include "nv40.h"
 
+const struct nvkm_specsrc
+g84_vfetch_sources[] = {
+   { 0x400c0c, (const struct nvkm_specmux[]) {
+   { 0x3, 0, "unk0" },
+   {}
+   }, "pgraph_vfetch_unk0c" },
+   {}
+};
+
+static const struct nvkm_specsrc
+g84_crop_sources[] = {
+   { 0x407008, (const struct nvkm_specmux[]) {
+   { 0xf, 0, "sel0", true },
+   { 0x7, 16, "sel1", true },
+   {}
+   }, "pgraph_rop0_crop_pm_mux" },
+   {}
+};
+
+static const struct nvkm_specsrc
+g84_tex_sources[] = {
+   { 0x408808, (const struct nvkm_specmux[]) {
+   { 0xf, 0, "unk0" },
+   {}
+   }, "pgraph_tpc0_tex_unk08" },
+   {}
+};
+
 static const struct nvkm_specdom
 g84_pm[] = {
{ 0x20, (const struct nvkm_specsig[]) {
{}
}, &nv40_perfctr_func },
-   { 0x20, (const struct nvkm_specsig[]) {
+   { 0xf0, (const struct nvkm_specsig[]) {
+   { 0xbd, "pc01_gr_idle" },
+   { 0x5e, "pc01_strmout_00" },
+   { 0x5f, "pc01_strmout_01" },
+   { 0xd2, "pc01_trast_00" },
+   { 0xd3, "pc01_trast_01" },
+   { 0xd4, "pc01_trast_02" },
+   { 0xd5, "pc01_trast_03" },
+   { 0xd8, "pc01_trast_04" },
+   { 0xd9, "pc01_trast_05" },
+   { 0x5c, "pc01_vattr_00" },
+   { 0x5d, "pc01_vattr_01" },
+   { 0x66, "pc01_vfetch_00", g84_vfetch_sources },
+   { 0x67, "pc01_vfetch_01", g84_vfetch_sources },
+   { 0x68, "pc01_vfetch_02", g84_vfetch_sources },
+   { 0x69, "pc01_vfetch_03", g84_vfetch_sour

[Nouveau] [PATCH RFC 12/20] pm: add concept of sources

2015-06-07 Thread Samuel Pitoiset
From: Samuel Pitoiset 

A source (or multiplexer) is a tuple addr+mask+shift which allows to
control a block of signals. The maximum number of sources that a signal
can define is arbitrary limited to 8 and this should be large enough.
This patch allows to define multi-level of sources for a signal.

Each different sources are stored to a global list and will be exposed
to the userspace through the nvif interface in order to avoid conflicts.

Signed-off-by: Samuel Pitoiset 
---
 drm/nouveau/include/nvkm/engine/pm.h |  1 +
 drm/nouveau/nvkm/engine/pm/base.c| 82 ++--
 drm/nouveau/nvkm/engine/pm/priv.h| 24 +++
 3 files changed, 103 insertions(+), 4 deletions(-)

diff --git a/drm/nouveau/include/nvkm/engine/pm.h 
b/drm/nouveau/include/nvkm/engine/pm.h
index 6c2d057..130b545 100644
--- a/drm/nouveau/include/nvkm/engine/pm.h
+++ b/drm/nouveau/include/nvkm/engine/pm.h
@@ -11,6 +11,7 @@ struct nvkm_pm {
void *profile_data;
 
struct list_head domains;
+   struct list_head sources;
u32 sequence;
 };
 
diff --git a/drm/nouveau/nvkm/engine/pm/base.c 
b/drm/nouveau/nvkm/engine/pm/base.c
index 610c0ca..dfafefd 100644
--- a/drm/nouveau/nvkm/engine/pm/base.c
+++ b/drm/nouveau/nvkm/engine/pm/base.c
@@ -434,6 +434,67 @@ nvkm_pm_cclass = {
  * PPM engine/subdev functions
  
**/
 int
+nvkm_perfsrc_new(struct nvkm_pm *ppm, struct nvkm_perfsig *sig,
+const struct nvkm_specsrc *spec)
+{
+   const struct nvkm_specsrc *ssrc;
+   const struct nvkm_specmux *smux;
+   struct nvkm_perfsrc *src;
+   u8 source_nr = 0;
+
+   if (!spec) {
+   /* No sources are defined for this signal. */
+   return 0;
+   }
+
+   ssrc = spec;
+   while (ssrc->name) {
+   smux = ssrc->mux;
+   while (smux->name) {
+   bool found = false;
+   u8 source_id = 0;
+   u32 len;
+
+   list_for_each_entry(src, &ppm->sources, head) {
+   if (src->addr == ssrc->addr &&
+   src->shift == smux->shift) {
+   found = true;
+   break;
+   }
+   source_id++;
+   }
+
+   if (!found) {
+   src = kzalloc(sizeof(*src), GFP_KERNEL);
+   if (!src)
+   return -ENOMEM;
+
+   src->addr   = ssrc->addr;
+   src->mask   = smux->mask;
+   src->shift  = smux->shift;
+   src->enable = smux->enable;
+
+   len = strlen(ssrc->name) +
+ strlen(smux->name) + 2;
+   src->name = kzalloc(len, GFP_KERNEL);
+   if (!src->name)
+   return -ENOMEM;
+   snprintf(src->name, len, "%s_%s", ssrc->name,
+smux->name);
+
+   list_add_tail(&src->head, &ppm->sources);
+   }
+
+   sig->source[source_nr++] = source_id + 1;
+   smux++;
+   }
+   ssrc++;
+   }
+
+   return 0;
+}
+
+int
 nvkm_perfdom_new(struct nvkm_pm *ppm, const char *name, u32 mask,
 u32 base, u32 size_unit, u32 size_domain,
 const struct nvkm_specdom *spec)
@@ -441,7 +502,7 @@ nvkm_perfdom_new(struct nvkm_pm *ppm, const char *name, u32 
mask,
const struct nvkm_specdom *sdom;
const struct nvkm_specsig *ssig;
struct nvkm_perfdom *dom;
-   int i;
+   int ret, i;
 
for (i = 0; i == 0 || mask; i++) {
u32 addr = base + (i * size_unit);
@@ -473,7 +534,12 @@ nvkm_perfdom_new(struct nvkm_pm *ppm, const char *name, 
u32 mask,
 
ssig = (sdom++)->signal;
while (ssig->name) {
-   dom->signal[ssig->signal].name = ssig->name;
+   struct nvkm_perfsig *sig =
+   &dom->signal[ssig->signal];
+   sig->name = ssig->name;
+   ret = nvkm_perfsrc_new(ppm, sig, ssig->source);
+   if (ret)
+   return ret;
ssig++;
}
 
@@ -504,13 +570,20 @@ void
 _nv

[Nouveau] [PATCH RFC 08/20] pm: allow to query signals by domain

2015-06-07 Thread Samuel Pitoiset
This will allow to configure performance counters with hardware signal
indexes instead of user-readable names in an upcoming patch.

Signed-off-by: Samuel Pitoiset 
---
 bin/nv_perfmon.c  | 185 --
 drm/nouveau/include/nvif/class.h  |   3 +-
 drm/nouveau/nvkm/engine/pm/base.c |  36 +++-
 3 files changed, 150 insertions(+), 74 deletions(-)

diff --git a/bin/nv_perfmon.c b/bin/nv_perfmon.c
index 30a3138..958520e 100644
--- a/bin/nv_perfmon.c
+++ b/bin/nv_perfmon.c
@@ -36,8 +36,7 @@
 #include 
 
 static struct nvif_device *device;
-static char **signals;
-static int nr_signals;
+static int nr_signals; /* number of signals for all domains */
 
 #define SEC_US  100
 #define REFRESH_PERIOD SEC_US
@@ -247,6 +246,17 @@ ui_menu_win = {
  *
  
**/
 
+struct ui_perfmon_dom {
+   struct list_head head;
+   struct list_head list;
+   u8 id;
+};
+
+struct ui_perfmon_sig {
+   struct list_head head;
+   char *name;
+};
+
 struct ui_main {
struct list_head head;
u32 handle;
@@ -258,6 +268,7 @@ struct ui_main {
 };
 
 static struct list_head ui_main_list = LIST_HEAD_INIT(ui_main_list);
+static struct list_head ui_doms_list = LIST_HEAD_INIT(ui_doms_list);
 static u32 ui_main_handle = 0xc000;
 
 static void
@@ -269,32 +280,134 @@ ui_main_remove(struct ui_main *item)
 }
 
 static void
+ui_perfmon_query_signals(struct nvif_object *perfmon,
+struct ui_perfmon_dom *dom)
+{
+   struct nvif_perfmon_query_signal_v0 args = {};
+   struct ui_perfmon_sig *sig;
+   int ret;
+
+   args.domain = dom->id;
+   do {
+   u32 prev_iter = args.iter;
+
+   args.name[0] = '\0';
+   ret = nvif_mthd(perfmon, NVIF_PERFMON_V0_QUERY_SIGNAL,
+   &args, sizeof(args));
+   assert(ret == 0);
+
+   if (prev_iter) {
+   nr_signals++;
+   sig = calloc(1, sizeof(*sig));
+   sig->name = malloc(sizeof(args.name));
+   strncpy(sig->name, args.name, sizeof(args.name));
+   list_add_tail(&sig->head, &dom->list);
+
+   args.iter = prev_iter;
+   ret = nvif_mthd(perfmon, NVIF_PERFMON_V0_QUERY_SIGNAL,
+   &args, sizeof(args));
+   assert(ret == 0);
+   }
+   } while (args.iter != 0x);
+}
+
+static void
+ui_perfmon_query_domains(struct nvif_object *perfmon)
+{
+   struct nvif_perfmon_query_domain_v0 args = {};
+   struct ui_perfmon_dom *dom;
+   int ret;
+
+   assert(ret == 0);
+   do {
+   u8 prev_iter = args.iter;
+
+   ret = nvif_mthd(perfmon, NVIF_PERFMON_V0_QUERY_DOMAIN,
+   &args, sizeof(args));
+   assert(ret == 0);
+
+   if (prev_iter) {
+   dom = calloc(1, sizeof(*dom));
+   dom->id = args.id;
+   INIT_LIST_HEAD(&dom->list);
+   list_add_tail(&dom->head, &ui_doms_list);
+
+   args.iter = prev_iter;
+   ret = nvif_mthd(perfmon, NVIF_PERFMON_V0_QUERY_DOMAIN,
+   &args, sizeof(args));
+   assert(ret == 0);
+
+   /* query available signals for the domain */
+   ui_perfmon_query_signals(perfmon, dom);
+   }
+   } while (args.iter != 0xff);
+}
+
+static void
+ui_perfmon_init(void)
+{
+   struct nvif_object perfmon;
+   int ret;
+
+   ret = nvif_object_init(nvif_object(device), NULL, 0xdeadbeef,
+  NVIF_IOCTL_NEW_V0_PERFMON, NULL, 0, &perfmon);
+   assert(ret == 0);
+
+   /* query available domains for the device */
+   ui_perfmon_query_domains(&perfmon);
+
+   nvif_object_fini(&perfmon);
+}
+
+static void
+ui_perfmon_fini(void)
+{
+   struct ui_perfmon_dom *dom, *next_dom;
+   struct ui_perfmon_sig *sig, *next_sig;
+
+   list_for_each_entry_safe(dom, next_dom, &ui_doms_list, head) {
+   list_for_each_entry_safe(sig, next_sig, &dom->list, head) {
+   list_del(&sig->head);
+   free(sig->name);
+   free(sig);
+   }
+   list_del(&dom->head);
+   free(dom);
+   }
+}
+
+static void
 ui_main_select(void)
 {
struct ui_main *item, *temp;
-   int ret, i;
+   struct ui_perfmon_dom *dom;
+   struct ui_perfmon_sig *sig;
+   int ret;
 
list_for_each_entry_safe(item, temp, &ui_main_list, head) {
ui_mai

[Nouveau] [PATCH RFC 07/20] pm: implement NVIF_PERFMON_V0_QUERY_DOMAIN method

2015-06-07 Thread Samuel Pitoiset
This allows to query the number of available domains, including the
number of hardware counter and the number of signals per domain.

Signed-off-by: Samuel Pitoiset 
---
 drm/nouveau/include/nvif/class.h  | 11 -
 drm/nouveau/nvkm/engine/pm/base.c | 86 +++
 2 files changed, 96 insertions(+), 1 deletion(-)

diff --git a/drm/nouveau/include/nvif/class.h b/drm/nouveau/include/nvif/class.h
index 11935a0..0b28929 100644
--- a/drm/nouveau/include/nvif/class.h
+++ b/drm/nouveau/include/nvif/class.h
@@ -251,7 +251,16 @@ struct gf110_dma_v0 {
  * perfmon
  
**/
 
-#define NVIF_PERFMON_V0_QUERY_SIGNAL   0x00
+#define NVIF_PERFMON_V0_QUERY_DOMAIN   0x00
+#define NVIF_PERFMON_V0_QUERY_SIGNAL   0x01
+
+struct nvif_perfmon_query_domain_v0 {
+   __u8  version;
+   __u8  id;
+   __u8  counter_nr;
+   __u8  iter;
+   __u32 signal_nr;
+};
 
 struct nvif_perfmon_query_signal_v0 {
__u8  version;
diff --git a/drm/nouveau/nvkm/engine/pm/base.c 
b/drm/nouveau/nvkm/engine/pm/base.c
index 2f85147..3d9bcbc 100644
--- a/drm/nouveau/nvkm/engine/pm/base.c
+++ b/drm/nouveau/nvkm/engine/pm/base.c
@@ -34,6 +34,45 @@
 #define QUAD_MASK 0x0f
 #define QUAD_FREE 0x01
 
+static u8
+nvkm_pm_count_perfdom(struct nvkm_pm *ppm)
+{
+   struct nvkm_perfdom *dom;
+   u8 domain_nr = 0;
+
+   list_for_each_entry(dom, &ppm->domains, head)
+   domain_nr++;
+   return domain_nr;
+}
+
+static u32
+nvkm_perfdom_count_perfsig(struct nvkm_perfdom *dom)
+{
+   u32 signal_nr = 0;
+   int i;
+
+   if (dom) {
+   for (i = 0; i < dom->signal_nr; i++) {
+   if (dom->signal[i].name)
+   signal_nr++;
+   }
+   }
+   return signal_nr;
+}
+
+static struct nvkm_perfdom *
+nvkm_perfdom_find(struct nvkm_pm *ppm, int di)
+{
+   struct nvkm_perfdom *dom;
+   int tmp = 0;
+
+   list_for_each_entry(dom, &ppm->domains, head) {
+   if (tmp++ == di)
+   return dom;
+   }
+   return NULL;
+}
+
 static struct nvkm_perfsig *
 nvkm_perfsig_find_(struct nvkm_perfdom *dom, const char *name, u32 size)
 {
@@ -83,6 +122,51 @@ nvkm_perfsig_find(struct nvkm_pm *ppm, const char *name, 
u32 size,
  * Perfmon object classes
  
**/
 static int
+nvkm_perfmon_mthd_query_domain(struct nvkm_object *object, void *data, u32 
size)
+{
+   union {
+   struct nvif_perfmon_query_domain_v0 v0;
+   } *args = data;
+   struct nvkm_pm *ppm = (void *)object->engine;
+   struct nvkm_perfdom *dom;
+   u8 domain_nr;
+   int di, ret;
+
+   nv_ioctl(object, "perfmon query domain size %d\n", size);
+   if (nvif_unpack(args->v0, 0, 0, false)) {
+   nv_ioctl(object, "perfmon domain vers %d iter %02x\n",
+args->v0.version, args->v0.iter);
+   di = (args->v0.iter & 0xff) - 1;
+   } else
+   return ret;
+
+   domain_nr = nvkm_pm_count_perfdom(ppm);
+   if (di >= (int)domain_nr)
+   return -EINVAL;
+
+   if (di >= 0) {
+   dom = nvkm_perfdom_find(ppm, di);
+   if (dom == NULL)
+   return -EINVAL;
+
+   args->v0.id = di;
+   args->v0.signal_nr  = nvkm_perfdom_count_perfsig(dom);
+
+   /* Currently only global counters (PCOUNTER) are implemented
+* but this will be different for local counters (MP). */
+   args->v0.counter_nr = 4;
+   }
+
+   if (++di < domain_nr) {
+   args->v0.iter = ++di;
+   return 0;
+   }
+
+   args->v0.iter = 0xff;
+   return 0;
+}
+
+static int
 nvkm_perfmon_mthd_query_signal(struct nvkm_object *object, void *data, u32 
size)
 {
union {
@@ -145,6 +229,8 @@ static int
 nvkm_perfmon_mthd(struct nvkm_object *object, u32 mthd, void *data, u32 size)
 {
switch (mthd) {
+   case NVIF_PERFMON_V0_QUERY_DOMAIN:
+   return nvkm_perfmon_mthd_query_domain(object, data, size);
case NVIF_PERFMON_V0_QUERY_SIGNAL:
return nvkm_perfmon_mthd_query_signal(object, data, size);
default:
-- 
2.4.2

___
Nouveau mailing list
Nouveau@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/nouveau


[Nouveau] [PATCH RFC 10/20] pm: use hardware signals indexes instead of user-readable names

2015-06-07 Thread Samuel Pitoiset
Signed-off-by: Samuel Pitoiset 
---
 bin/nv_perfmon.c  |  6 +++--
 drm/nouveau/include/nvif/class.h  | 11 ++---
 drm/nouveau/nvkm/engine/pm/base.c | 52 +--
 3 files changed, 23 insertions(+), 46 deletions(-)

diff --git a/bin/nv_perfmon.c b/bin/nv_perfmon.c
index 043d864..50c 100644
--- a/bin/nv_perfmon.c
+++ b/bin/nv_perfmon.c
@@ -255,6 +255,7 @@ struct ui_perfmon_dom {
 struct ui_perfmon_sig {
struct list_head head;
char *name;
+   u8 signal;
 };
 
 struct ui_main {
@@ -299,6 +300,7 @@ ui_perfmon_query_signals(struct nvif_object *perfmon,
if (prev_iter) {
nr_signals++;
sig = calloc(1, sizeof(*sig));
+   sig->signal = args.signal;
sig->name = malloc(sizeof(args.name));
strncpy(sig->name, args.name, sizeof(args.name));
list_add_tail(&sig->head, &dom->list);
@@ -392,14 +394,14 @@ ui_main_select(void)
list_for_each_entry(sig, &dom->list, head) {
struct nvif_perfctr_v0 args = {
.logic_op = 0x,
+   .domain = dom->id,
};
 
item = calloc(1, sizeof(*item));
item->handle = ui_main_handle++;
item->name = sig->name;
 
-   strncpy(args.name[0], item->name, sizeof(args.name[0]));
-
+   args.signal[0] = sig->signal;
ret = nvif_object_init(nvif_object(device), NULL,
   item->handle,
   NVIF_IOCTL_NEW_V0_PERFCTR,
diff --git a/drm/nouveau/include/nvif/class.h b/drm/nouveau/include/nvif/class.h
index 871247c..9e4db3a 100644
--- a/drm/nouveau/include/nvif/class.h
+++ b/drm/nouveau/include/nvif/class.h
@@ -267,7 +267,8 @@ struct nvif_perfmon_query_signal_v0 {
__u8  version;
__u8  domain;
__u16 iter;
-   __u8  pad03[4];
+   __u8  signal;
+   __u8  pad04[3];
char  name[64];
 };
 
@@ -278,10 +279,12 @@ struct nvif_perfmon_query_signal_v0 {
 
 struct nvif_perfctr_v0 {
__u8  version;
-   __u8  pad01[1];
+   __u8  domain;
+   __u8  pad02[2];
__u16 logic_op;
-   __u8  pad04[4];
-   char  name[4][64];
+   __u8  pad04[2];
+   __u8  signal[4];
+   __u8  pad06[4];
 };
 
 #define NVIF_PERFCTR_V0_SAMPLE 0x00
diff --git a/drm/nouveau/nvkm/engine/pm/base.c 
b/drm/nouveau/nvkm/engine/pm/base.c
index fab0598..71834b9 100644
--- a/drm/nouveau/nvkm/engine/pm/base.c
+++ b/drm/nouveau/nvkm/engine/pm/base.c
@@ -73,49 +73,22 @@ nvkm_perfdom_find(struct nvkm_pm *ppm, int di)
return NULL;
 }
 
-static struct nvkm_perfsig *
-nvkm_perfsig_find_(struct nvkm_perfdom *dom, const char *name, u32 size)
-{
-   char path[64];
-   int i;
-
-   if (name[0] != '/') {
-   for (i = 0; i < dom->signal_nr; i++) {
-   if ( dom->signal[i].name &&
-   !strncmp(name, dom->signal[i].name, size))
-   return &dom->signal[i];
-   }
-   } else {
-   for (i = 0; i < dom->signal_nr; i++) {
-   snprintf(path, sizeof(path), "/%s/%02x", dom->name, i);
-   if (!strncmp(name, path, size))
-   return &dom->signal[i];
-   }
-   }
-
-   return NULL;
-}
-
 struct nvkm_perfsig *
-nvkm_perfsig_find(struct nvkm_pm *ppm, const char *name, u32 size,
+nvkm_perfsig_find(struct nvkm_pm *ppm, uint8_t di, uint8_t si,
  struct nvkm_perfdom **pdom)
 {
struct nvkm_perfdom *dom = *pdom;
-   struct nvkm_perfsig *sig;
 
if (dom == NULL) {
-   list_for_each_entry(dom, &ppm->domains, head) {
-   sig = nvkm_perfsig_find_(dom, name, size);
-   if (sig) {
-   *pdom = dom;
-   return sig;
-   }
-   }
-
-   return NULL;
+   dom = nvkm_perfdom_find(ppm, di);
+   if (dom == NULL)
+   return NULL;
+   *pdom = dom;
}
 
-   return nvkm_perfsig_find_(dom, name, size);
+   if (!dom->signal[si].name)
+   return NULL;
+   return &dom->signal[si];
 }
 
 
/***
@@ -200,6 +173,7 @@ nvkm_perfmon_mthd_query_signal(struct nvkm_object *object, 
void *data, u32 size)
} else {
strncpy(a

[Nouveau] [PATCH RFC 11/20] pm: allow to monitor hardware signal index 0x00

2015-06-07 Thread Samuel Pitoiset
This signal index must be always allowed even if it's not clearly
defined in a domain in order to monitor a counter like 0x03020100
because it's the default value of signals.

Signed-off-by: Samuel Pitoiset 
---
 drm/nouveau/nvkm/engine/pm/base.c  | 4 ++--
 drm/nouveau/nvkm/engine/pm/gf100.c | 6 --
 drm/nouveau/nvkm/engine/pm/nv40.c  | 6 --
 3 files changed, 10 insertions(+), 6 deletions(-)

diff --git a/drm/nouveau/nvkm/engine/pm/base.c 
b/drm/nouveau/nvkm/engine/pm/base.c
index 71834b9..610c0ca 100644
--- a/drm/nouveau/nvkm/engine/pm/base.c
+++ b/drm/nouveau/nvkm/engine/pm/base.c
@@ -333,10 +333,10 @@ nvkm_perfctr_ctor(struct nvkm_object *parent, struct 
nvkm_object *engine,
} else
return ret;
 
-   for (i = 0; i < ARRAY_SIZE(args->v0.signal) && args->v0.signal[i]; i++) 
{
+   for (i = 0; i < ARRAY_SIZE(args->v0.signal); i++) {
sig[i] = nvkm_perfsig_find(ppm, args->v0.domain,
   args->v0.signal[i], &dom);
-   if (!sig[i])
+   if (args->v0.signal[i] && !sig[i])
return -EINVAL;
}
 
diff --git a/drm/nouveau/nvkm/engine/pm/gf100.c 
b/drm/nouveau/nvkm/engine/pm/gf100.c
index 69303b5..41350d6 100644
--- a/drm/nouveau/nvkm/engine/pm/gf100.c
+++ b/drm/nouveau/nvkm/engine/pm/gf100.c
@@ -48,8 +48,10 @@ gf100_perfctr_init(struct nvkm_pm *ppm, struct nvkm_perfdom 
*dom,
u32 src = 0x;
int i;
 
-   for (i = 0; i < 4 && ctr->signal[i]; i++)
-   src |= (ctr->signal[i] - dom->signal) << (i * 8);
+   for (i = 0; i < 4; i++) {
+   if (ctr->signal[i])
+   src |= (ctr->signal[i] - dom->signal) << (i * 8);
+   }
 
nv_wr32(priv, dom->addr + 0x09c, 0x00040002);
nv_wr32(priv, dom->addr + 0x100, 0x);
diff --git a/drm/nouveau/nvkm/engine/pm/nv40.c 
b/drm/nouveau/nvkm/engine/pm/nv40.c
index ff22f06..603874e 100644
--- a/drm/nouveau/nvkm/engine/pm/nv40.c
+++ b/drm/nouveau/nvkm/engine/pm/nv40.c
@@ -33,8 +33,10 @@ nv40_perfctr_init(struct nvkm_pm *ppm, struct nvkm_perfdom 
*dom,
u32 src = 0x;
int i;
 
-   for (i = 0; i < 4 && ctr->signal[i]; i++)
-   src |= (ctr->signal[i] - dom->signal) << (i * 8);
+   for (i = 0; i < 4; i++) {
+   if (ctr->signal[i])
+   src |= (ctr->signal[i] - dom->signal) << (i * 8);
+   }
 
nv_wr32(priv, 0x00a7c0 + dom->addr, 0x0001);
nv_wr32(priv, 0x00a400 + dom->addr + (cntr->base.slot * 0x40), src);
-- 
2.4.2

___
Nouveau mailing list
Nouveau@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/nouveau


[Nouveau] [PATCH RFC 02/20] pm: fix a potential race condition when creating an engine context

2015-06-07 Thread Samuel Pitoiset
There is always the possiblity that the ppm->context pointer would get
partially updated and accidentally would equal ctx. This would allow two
contexts to co-exist, which is not acceptable. Moving the test to the
critical section takes care of this problem.

Signed-off-by: Samuel Pitoiset 
Signed-off-by: Martin Peres 
---
 drm/nouveau/nvkm/engine/pm/base.c | 7 +++
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/drm/nouveau/nvkm/engine/pm/base.c 
b/drm/nouveau/nvkm/engine/pm/base.c
index 274457c..4cf36a3 100644
--- a/drm/nouveau/nvkm/engine/pm/base.c
+++ b/drm/nouveau/nvkm/engine/pm/base.c
@@ -358,12 +358,11 @@ nvkm_perfctx_ctor(struct nvkm_object *parent, struct 
nvkm_object *engine,
mutex_lock(&nv_subdev(ppm)->mutex);
if (ppm->context == NULL)
ppm->context = ctx;
-   mutex_unlock(&nv_subdev(ppm)->mutex);
-
if (ctx != ppm->context)
-   return -EBUSY;
+   ret = -EBUSY;
+   mutex_unlock(&nv_subdev(ppm)->mutex);
 
-   return 0;
+   return ret;
 }
 
 struct nvkm_oclass
-- 
2.4.2

___
Nouveau mailing list
Nouveau@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/nouveau


[Nouveau] [PATCH RFC 06/20] pm: prevent creating a perfctr object when signals are not found

2015-06-07 Thread Samuel Pitoiset
Since a new class has been introduced to query signals, we can now
return an error when the userspace wants to monitor unknown signals.

Signed-off-by: Samuel Pitoiset 
---
 drm/nouveau/nvkm/engine/pm/base.c | 6 --
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/drm/nouveau/nvkm/engine/pm/base.c 
b/drm/nouveau/nvkm/engine/pm/base.c
index cb88170..2f85147 100644
--- a/drm/nouveau/nvkm/engine/pm/base.c
+++ b/drm/nouveau/nvkm/engine/pm/base.c
@@ -294,6 +294,9 @@ nvkm_perfctr_ctor(struct nvkm_object *parent, struct 
nvkm_object *engine,
return -EINVAL;
}
 
+   if (!dom)
+   return -EINVAL;
+
ret = nvkm_object_create(parent, engine, oclass, 0, &ctr);
*pobject = nv_object(ctr);
if (ret)
@@ -305,8 +308,7 @@ nvkm_perfctr_ctor(struct nvkm_object *parent, struct 
nvkm_object *engine,
ctr->signal[1] = sig[1];
ctr->signal[2] = sig[2];
ctr->signal[3] = sig[3];
-   if (dom)
-   list_add_tail(&ctr->head, &dom->list);
+   list_add_tail(&ctr->head, &dom->list);
return 0;
 }
 
-- 
2.4.2

___
Nouveau mailing list
Nouveau@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/nouveau


[Nouveau] [PATCH RFC 05/20] pm: reorganize the nvif interface

2015-06-07 Thread Samuel Pitoiset
This commit introduces the NVIF_IOCTL_NEW_V0_PERFMON class which will be
used in order to query domains, signals and sources. This separates the
querying and the counting interface.

Signed-off-by: Samuel Pitoiset 
---
 bin/nv_perfmon.c  | 12 ++--
 drm/nouveau/include/nvif/class.h  | 26 --
 drm/nouveau/include/nvif/ioctl.h  |  5 +++--
 drm/nouveau/nvkm/engine/pm/base.c | 38 --
 4 files changed, 57 insertions(+), 24 deletions(-)

diff --git a/bin/nv_perfmon.c b/bin/nv_perfmon.c
index a8c5838..30a3138 100644
--- a/bin/nv_perfmon.c
+++ b/bin/nv_perfmon.c
@@ -600,7 +600,7 @@ main(int argc, char **argv)
const char *cfg = NULL;
const char *dbg = "error";
u64 dev = ~0ULL;
-   struct nvif_perfctr_query_v0 args = {};
+   struct nvif_perfmon_query_signal_v0 args = {};
struct nvif_client *client;
struct nvif_object object;
int ret, c, k;
@@ -644,15 +644,14 @@ main(int argc, char **argv)
}
 
ret = nvif_object_init(nvif_object(device), NULL, 0xdeadbeef,
-  NVIF_IOCTL_NEW_V0_PERFCTR,
-  &(struct nvif_perfctr_v0) {
-  }, sizeof(struct nvif_perfctr_v0), &object);
+  NVIF_IOCTL_NEW_V0_PERFMON, NULL, 0, &object);
assert(ret == 0);
do {
u32 prev_iter = args.iter;
 
args.name[0] = '\0';
-   ret = nvif_mthd(&object, NVIF_PERFCTR_V0_QUERY, &args, 
sizeof(args));
+   ret = nvif_mthd(&object, NVIF_PERFMON_V0_QUERY_SIGNAL,
+   &args, sizeof(args));
assert(ret == 0);
 
if (prev_iter) {
@@ -663,7 +662,8 @@ main(int argc, char **argv)
args.iter = prev_iter;
strncpy(signals[nr_signals - 1], args.name,
sizeof(args.name));
-   ret = nvif_mthd(&object, NVIF_PERFCTR_V0_QUERY, &args, 
sizeof(args));
+   ret = nvif_mthd(&object, NVIF_PERFMON_V0_QUERY_SIGNAL,
+   &args, sizeof(args));
assert(ret == 0);
}
} while (args.iter != 0x);
diff --git a/drm/nouveau/include/nvif/class.h b/drm/nouveau/include/nvif/class.h
index 64f8b2f..11935a0 100644
--- a/drm/nouveau/include/nvif/class.h
+++ b/drm/nouveau/include/nvif/class.h
@@ -251,6 +251,20 @@ struct gf110_dma_v0 {
  * perfmon
  
**/
 
+#define NVIF_PERFMON_V0_QUERY_SIGNAL   0x00
+
+struct nvif_perfmon_query_signal_v0 {
+   __u8  version;
+   __u8  pad01[3];
+   __u32 iter;
+   char  name[64];
+};
+
+
+/***
+ * perfctr
+ 
**/
+
 struct nvif_perfctr_v0 {
__u8  version;
__u8  pad01[1];
@@ -259,16 +273,8 @@ struct nvif_perfctr_v0 {
char  name[4][64];
 };
 
-#define NVIF_PERFCTR_V0_QUERY  0x00
-#define NVIF_PERFCTR_V0_SAMPLE 0x01
-#define NVIF_PERFCTR_V0_READ   0x02
-
-struct nvif_perfctr_query_v0 {
-   __u8  version;
-   __u8  pad01[3];
-   __u32 iter;
-   char  name[64];
-};
+#define NVIF_PERFCTR_V0_SAMPLE 0x00
+#define NVIF_PERFCTR_V0_READ   0x01
 
 struct nvif_perfctr_sample {
 };
diff --git a/drm/nouveau/include/nvif/ioctl.h b/drm/nouveau/include/nvif/ioctl.h
index 4cd8e32..517cd27 100644
--- a/drm/nouveau/include/nvif/ioctl.h
+++ b/drm/nouveau/include/nvif/ioctl.h
@@ -49,8 +49,9 @@ struct nvif_ioctl_new_v0 {
__u64 token;
__u32 handle;
 /* these class numbers are made up by us, and not nvidia-assigned */
-#define NVIF_IOCTL_NEW_V0_PERFCTR0x
-#define NVIF_IOCTL_NEW_V0_CONTROL0xfffe
+#define NVIF_IOCTL_NEW_V0_PERFMON0x
+#define NVIF_IOCTL_NEW_V0_PERFCTR0xfffe
+#define NVIF_IOCTL_NEW_V0_CONTROL0xfffd
__u32 oclass;
__u8  data[];   /* class data (class.h) */
 };
diff --git a/drm/nouveau/nvkm/engine/pm/base.c 
b/drm/nouveau/nvkm/engine/pm/base.c
index 7b07e8b..cb88170 100644
--- a/drm/nouveau/nvkm/engine/pm/base.c
+++ b/drm/nouveau/nvkm/engine/pm/base.c
@@ -83,10 +83,10 @@ nvkm_perfsig_find(struct nvkm_

[Nouveau] [PATCH RFC 04/20] pm: remove unused nvkm_perfsig_wrap() function

2015-06-07 Thread Samuel Pitoiset
Signed-off-by: Samuel Pitoiset 
Reviewed-by: Martin Peres 
---
 drm/nouveau/nvkm/engine/pm/base.c | 20 
 drm/nouveau/nvkm/engine/pm/priv.h |  4 
 2 files changed, 24 deletions(-)

diff --git a/drm/nouveau/nvkm/engine/pm/base.c 
b/drm/nouveau/nvkm/engine/pm/base.c
index 4cf36a3..7b07e8b 100644
--- a/drm/nouveau/nvkm/engine/pm/base.c
+++ b/drm/nouveau/nvkm/engine/pm/base.c
@@ -79,26 +79,6 @@ nvkm_perfsig_find(struct nvkm_pm *ppm, const char *name, u32 
size,
return nvkm_perfsig_find_(dom, name, size);
 }
 
-struct nvkm_perfctr *
-nvkm_perfsig_wrap(struct nvkm_pm *ppm, const char *name,
- struct nvkm_perfdom **pdom)
-{
-   struct nvkm_perfsig *sig;
-   struct nvkm_perfctr *ctr;
-
-   sig = nvkm_perfsig_find(ppm, name, strlen(name), pdom);
-   if (!sig)
-   return NULL;
-
-   ctr = kzalloc(sizeof(*ctr), GFP_KERNEL);
-   if (ctr) {
-   ctr->signal[0] = sig;
-   ctr->logic_op = 0x;
-   }
-
-   return ctr;
-}
-
 
/***
  * Perfmon object classes
  
**/
diff --git a/drm/nouveau/nvkm/engine/pm/priv.h 
b/drm/nouveau/nvkm/engine/pm/priv.h
index 95796c7..06a6e60 100644
--- a/drm/nouveau/nvkm/engine/pm/priv.h
+++ b/drm/nouveau/nvkm/engine/pm/priv.h
@@ -31,10 +31,6 @@ struct nvkm_perfsig {
const char *name;
 };
 
-struct nvkm_perfdom;
-struct nvkm_perfctr *
-nvkm_perfsig_wrap(struct nvkm_pm *, const char *, struct nvkm_perfdom **);
-
 struct nvkm_specdom {
u16 signal_nr;
const struct nvkm_specsig *signal;
-- 
2.4.2

___
Nouveau mailing list
Nouveau@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/nouveau


[Nouveau] [PATCH RFC 00/20] expose global performance counters

2015-06-07 Thread Samuel Pitoiset
Hello,

This series exposes global performance counters (PCOUNTER) to the userspace
through the nvif interface by reworking most of the code related to the PM
engine.

This interface will allow the userspace to control and monitor complex hardware
events like the proprietary driver already does, for example with CUPTI and
PerfKit.

For now, this series only exposes performance counters on NV50, but this is
going to be pretty similar for other families. My plan is to submit more
patches for Fermi and Kepler after this series will be reviewed.

The code of this series can be found here:

http://cgit.freedesktop.org/~hakzsam/nouveau/log/?h=nouveau_perfmon

And the corresponding libdrm branch can be found here:

http://cgit.freedesktop.org/~hakzsam/drm/log/?h=nouveau_perfmon

A full example which exposes both compute and graphics hardware events on NV50
can be found here:

http://cgit.freedesktop.org/~hakzsam/perfevent

Most of the code will be implemented in mesa once the kernel interface is
going to be upstream and stable.

Below, you can find a summary of the series:

Patches 1-2:fix a bug related to the PM engine context
Patches 3-4:remove useless PMU signals and unused functions
Patches 5-6:reorganize the nvif interface to expose more stuff
Patches 7-11:   expose PCOUNTER domains to the userspace
Patches 12-14:  implement concept of sources (ie. multiplexers)
Patches 15-17:  allow to monitor complex hardware events
Patches 18: add compute/graphics signals/sources
Patches 19-20:  expose a software methods interface for controlling PM

Feel free to make a review.
Thanks in advance!

Samuel Pitoiset (20):
  pm: prevent freeing the wrong engine context
  pm: fix a potential race condition when creating an engine context
  pm: remove pmu signals
  pm: remove unused nvkm_perfsig_wrap() function
  pm: reorganize the nvif interface
  pm: prevent creating a perfctr object when signals are not found
  pm: implement NVIF_PERFMON_V0_QUERY_DOMAIN method
  pm: allow to query signals by domain
  pm: change signal iter to u16
  pm: use hardware signals indexes instead of user-readable names
  pm: allow to monitor hardware signal index 0x00
  pm: add concept of sources
  pm: allow to query the number of sources for a signal
  pm: implement NVIF_PERFMON_V0_QUERY_SOURCE method
  pm: allow the userspace to schedule hardware counters
  pm: allow to configure domains instead of simple counters
  pm: allow the userspace to configure sources
  pm/nv50: add compute and graphics signals/sources
  sw/nv50: add some private functions to factorize code
  sw/nv50: add and interface for controlling performance counters

 bin/nv_perfmon.c  | 324 
 drm/nouveau/include/nvif/class.h  |  68 +++-
 drm/nouveau/include/nvif/ioctl.h  |   5 +-
 drm/nouveau/include/nvkm/engine/pm.h  |   6 +-
 drm/nouveau/nvkm/engine/device/nv50.c |   2 +-
 drm/nouveau/nvkm/engine/pm/Kbuild |   2 +-
 drm/nouveau/nvkm/engine/pm/base.c | 685 +-
 drm/nouveau/nvkm/engine/pm/daemon.c   | 108 --
 drm/nouveau/nvkm/engine/pm/g84.c  | 101 -
 drm/nouveau/nvkm/engine/pm/gf100.c|  13 +-
 drm/nouveau/nvkm/engine/pm/gk104.c|   6 -
 drm/nouveau/nvkm/engine/pm/gk110.c|   4 -
 drm/nouveau/nvkm/engine/pm/gt200.c| 163 
 drm/nouveau/nvkm/engine/pm/gt215.c| 104 --
 drm/nouveau/nvkm/engine/pm/nv40.c |   8 +-
 drm/nouveau/nvkm/engine/pm/nv50.c | 136 ++-
 drm/nouveau/nvkm/engine/pm/priv.h |  53 ++-
 drm/nouveau/nvkm/engine/sw/nv50.c | 216 ++-
 drm/nouveau/nvkm/engine/sw/nv50.h |   6 +
 19 files changed, 1561 insertions(+), 449 deletions(-)
 delete mode 100644 drm/nouveau/nvkm/engine/pm/daemon.c
 create mode 100644 drm/nouveau/nvkm/engine/pm/gt200.c

-- 
2.4.2

___
Nouveau mailing list
Nouveau@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/nouveau


[Nouveau] [PATCH RFC 03/20] pm: remove pmu signals

2015-06-07 Thread Samuel Pitoiset
PDAEMON signals don't have to be exposed by the perfmon engine.

Signed-off-by: Samuel Pitoiset 
Reviewed-by: Martin Peres 
---
 drm/nouveau/include/nvkm/engine/pm.h |   4 --
 drm/nouveau/nvkm/engine/pm/Kbuild|   1 -
 drm/nouveau/nvkm/engine/pm/daemon.c  | 108 ---
 drm/nouveau/nvkm/engine/pm/gf100.c   |   5 --
 drm/nouveau/nvkm/engine/pm/gk104.c   |   6 --
 drm/nouveau/nvkm/engine/pm/gk110.c   |   4 --
 drm/nouveau/nvkm/engine/pm/gt215.c   |  20 +--
 drm/nouveau/nvkm/engine/pm/priv.h|   4 --
 8 files changed, 1 insertion(+), 151 deletions(-)
 delete mode 100644 drm/nouveau/nvkm/engine/pm/daemon.c

diff --git a/drm/nouveau/include/nvkm/engine/pm.h 
b/drm/nouveau/include/nvkm/engine/pm.h
index 93181bb..6c2d057 100644
--- a/drm/nouveau/include/nvkm/engine/pm.h
+++ b/drm/nouveau/include/nvkm/engine/pm.h
@@ -12,10 +12,6 @@ struct nvkm_pm {
 
struct list_head domains;
u32 sequence;
-
-   /*XXX: temp for daemon backend */
-   u32 pwr[8];
-   u32 last;
 };
 
 static inline struct nvkm_pm *
diff --git a/drm/nouveau/nvkm/engine/pm/Kbuild 
b/drm/nouveau/nvkm/engine/pm/Kbuild
index 413b609..c5ee8d5 100644
--- a/drm/nouveau/nvkm/engine/pm/Kbuild
+++ b/drm/nouveau/nvkm/engine/pm/Kbuild
@@ -1,5 +1,4 @@
 nvkm-y += nvkm/engine/pm/base.o
-nvkm-y += nvkm/engine/pm/daemon.o
 nvkm-y += nvkm/engine/pm/nv40.o
 nvkm-y += nvkm/engine/pm/nv50.o
 nvkm-y += nvkm/engine/pm/g84.o
diff --git a/drm/nouveau/nvkm/engine/pm/daemon.c 
b/drm/nouveau/nvkm/engine/pm/daemon.c
deleted file mode 100644
index a7a5f3a..000
--- a/drm/nouveau/nvkm/engine/pm/daemon.c
+++ /dev/null
@@ -1,108 +0,0 @@
-/*
- * Copyright 2013 Red Hat Inc.
- *
- * 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 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
- * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) 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.
- *
- * Authors: Ben Skeggs
- */
-#include "priv.h"
-
-static void
-pwr_perfctr_init(struct nvkm_pm *ppm, struct nvkm_perfdom *dom,
-struct nvkm_perfctr *ctr)
-{
-   u32 mask = 0x;
-   u32 ctrl = 0x0001;
-   int i;
-
-   for (i = 0; i < ARRAY_SIZE(ctr->signal) && ctr->signal[i]; i++)
-   mask |= 1 << (ctr->signal[i] - dom->signal);
-
-   nv_wr32(ppm, 0x10a504 + (ctr->slot * 0x10), mask);
-   nv_wr32(ppm, 0x10a50c + (ctr->slot * 0x10), ctrl);
-   nv_wr32(ppm, 0x10a50c + (ppm->last * 0x10), 0x0003);
-}
-
-static void
-pwr_perfctr_read(struct nvkm_pm *ppm, struct nvkm_perfdom *dom,
-struct nvkm_perfctr *ctr)
-{
-   ctr->ctr = ppm->pwr[ctr->slot];
-   ctr->clk = ppm->pwr[ppm->last];
-}
-
-static void
-pwr_perfctr_next(struct nvkm_pm *ppm, struct nvkm_perfdom *dom)
-{
-   int i;
-
-   for (i = 0; i <= ppm->last; i++) {
-   ppm->pwr[i] = nv_rd32(ppm, 0x10a508 + (i * 0x10));
-   nv_wr32(ppm, 0x10a508 + (i * 0x10), 0x8000);
-   }
-}
-
-static const struct nvkm_funcdom
-pwr_perfctr_func = {
-   .init = pwr_perfctr_init,
-   .read = pwr_perfctr_read,
-   .next = pwr_perfctr_next,
-};
-
-const struct nvkm_specdom
-gt215_pm_pwr[] = {
-   { 0x20, (const struct nvkm_specsig[]) {
-   { 0x00, "pwr_gr_idle" },
-   { 0x04, "pwr_bsp_idle" },
-   { 0x05, "pwr_vp_idle" },
-   { 0x06, "pwr_ppp_idle" },
-   { 0x13, "pwr_ce0_idle" },
-   {}
-   }, &pwr_perfctr_func },
-   {}
-};
-
-const struct nvkm_specdom
-gf100_pm_pwr[] = {
-   { 0x20, (const struct nvkm_specsig[]) {
-   { 0x00, "pwr_gr_idle" },
-   { 0x04, "pwr_bsp_idle" },
-   { 0x05, "pwr_vp_idle" },
-   { 0x06, "pwr_ppp_idle" },
-   { 0x13, "pwr_ce0_idle&

[Nouveau] [PATCH RFC 01/20] pm: prevent freeing the wrong engine context

2015-06-07 Thread Samuel Pitoiset
This fixes a crash when multiple PM engine contexts are created.

Signed-off-by: Samuel Pitoiset 
Reviewed-by: Martin Peres 
---
 drm/nouveau/nvkm/engine/pm/base.c | 7 +--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/drm/nouveau/nvkm/engine/pm/base.c 
b/drm/nouveau/nvkm/engine/pm/base.c
index 2006c44..274457c 100644
--- a/drm/nouveau/nvkm/engine/pm/base.c
+++ b/drm/nouveau/nvkm/engine/pm/base.c
@@ -332,9 +332,12 @@ static void
 nvkm_perfctx_dtor(struct nvkm_object *object)
 {
struct nvkm_pm *ppm = (void *)object->engine;
+   struct nvkm_perfctx *ctx = (void *)object;
+
mutex_lock(&nv_subdev(ppm)->mutex);
-   nvkm_engctx_destroy(&ppm->context->base);
-   ppm->context = NULL;
+   nvkm_engctx_destroy(&ctx->base);
+   if (ppm->context == ctx)
+   ppm->context = NULL;
mutex_unlock(&nv_subdev(ppm)->mutex);
 }
 
-- 
2.4.2

___
Nouveau mailing list
Nouveau@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/nouveau


[Nouveau] [RFC 0/3] implement nouveau-perfKit

2015-06-02 Thread Samuel Pitoiset
Hello,

A series I started a long time ago but now I need some feedbacks. :-)

This state tracker implements NVIDIA PerfKit 3.0.1 which is currently
only available on Windows 7+ for desktop graphics cards. A Linux/Android
implementation is provided by NVIDIA but only for NVIDIA Tegra K1.

This Gallium state tracker is loosely based on the VDPAU tracker and since
it uses the pipe_query interface, other drivers which expose performance
counters should be also able to expose them easily through PerfKit.

Unlike GL_AMD_performance_monitor, NVIDIA PerfKit allows to monitor
multi-passes events and the API supports different types of performance
counters (GPU, CPU, OpenGL).

Currently, only MP counters for NVC0:NVE4 Nouveau drivers are exposed.

To be able to use NVIDIA PerfKit from your OpenGL applications, you will
need to install the wrapper library which includes the headers of the API.

You can download this library from:
http://cgit.freedesktop.org/~hakzsam/libperfkit/

The wrapper library contains a large number of unit tests (~120) that helped
me to understand the API. More than 85% of test compliance for mesa.

Feel free to make a review of the perfkit state tracker and libperfkit.
Thanks!

Samuel Pitoiset (3):
  util: move LIST_FIRST_ENTRY from nv30_query.c to list.h
  util: add LIST_MOVE_TAIL to list.h
  st/perfkit: add a state tracker for NVIDIA PerfKit

 configure.ac   |  30 ++
 src/gallium/Makefile.am|   4 +
 src/gallium/drivers/nouveau/nv30/nv30_query.c  |   3 -
 src/gallium/state_trackers/perfkit/Makefile.am |  41 ++
 .../state_trackers/perfkit/Makefile.sources|   8 +
 src/gallium/state_trackers/perfkit/context.c   | 186 
 src/gallium/state_trackers/perfkit/counter.c   | 522 +
 src/gallium/state_trackers/perfkit/device.c|  91 
 src/gallium/state_trackers/perfkit/entrypoint.c|  78 +++
 src/gallium/state_trackers/perfkit/monitoring.c| 360 ++
 .../state_trackers/perfkit/perfkit_private.h   | 145 ++
 src/gallium/state_trackers/perfkit/util.c  |  56 +++
 src/gallium/targets/dri-perfkit.dyn|   3 +
 src/gallium/targets/perfkit/Makefile.am| 123 +
 src/gallium/targets/perfkit/perfkit.sym|   7 +
 src/gallium/targets/perfkit/target.c   |   1 +
 src/util/list.h|  12 +
 17 files changed, 1667 insertions(+), 3 deletions(-)
 create mode 100644 src/gallium/state_trackers/perfkit/Makefile.am
 create mode 100644 src/gallium/state_trackers/perfkit/Makefile.sources
 create mode 100644 src/gallium/state_trackers/perfkit/context.c
 create mode 100644 src/gallium/state_trackers/perfkit/counter.c
 create mode 100644 src/gallium/state_trackers/perfkit/device.c
 create mode 100644 src/gallium/state_trackers/perfkit/entrypoint.c
 create mode 100644 src/gallium/state_trackers/perfkit/monitoring.c
 create mode 100644 src/gallium/state_trackers/perfkit/perfkit_private.h
 create mode 100644 src/gallium/state_trackers/perfkit/util.c
 create mode 100644 src/gallium/targets/dri-perfkit.dyn
 create mode 100644 src/gallium/targets/perfkit/Makefile.am
 create mode 100644 src/gallium/targets/perfkit/perfkit.sym
 create mode 100644 src/gallium/targets/perfkit/target.c

-- 
2.4.2

___
Nouveau mailing list
Nouveau@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/nouveau


[Nouveau] [RFC 1/3] util: move LIST_FIRST_ENTRY from nv30_query.c to list.h

2015-06-02 Thread Samuel Pitoiset
Signed-off-by: Samuel Pitoiset 
---
 src/gallium/drivers/nouveau/nv30/nv30_query.c | 3 ---
 src/util/list.h   | 3 +++
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/src/gallium/drivers/nouveau/nv30/nv30_query.c 
b/src/gallium/drivers/nouveau/nv30/nv30_query.c
index 516ee83..80a9755 100644
--- a/src/gallium/drivers/nouveau/nv30/nv30_query.c
+++ b/src/gallium/drivers/nouveau/nv30/nv30_query.c
@@ -28,9 +28,6 @@
 #include "nv30/nv30_screen.h"
 #include "nv30/nv30_context.h"
 
-#define LIST_FIRST_ENTRY(__type, __item, __field) \
-   LIST_ENTRY(__type, (__item)->next, __field)
-
 struct nv30_query_object {
struct list_head list;
struct nouveau_heap *hw;
diff --git a/src/util/list.h b/src/util/list.h
index 9460347..fb566f5 100644
--- a/src/util/list.h
+++ b/src/util/list.h
@@ -126,6 +126,9 @@ static inline void list_validate(struct list_head *list)
 #define LIST_ENTRY(__type, __item, __field)   \
 ((__type *)(((char *)(__item)) - offsetof(__type, __field)))
 
+#define LIST_FIRST_ENTRY(__type, __item, __field) \
+   LIST_ENTRY(__type, (__item)->next, __field)
+
 #define LIST_IS_EMPTY(__list)   \
 ((__list)->next == (__list))
 
-- 
2.4.2

___
Nouveau mailing list
Nouveau@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/nouveau


[Nouveau] [RFC 3/3] st/perfkit: add a state tracker for NVIDIA PerfKit

2015-06-02 Thread Samuel Pitoiset
This state tracker implements NVIDIA PerfKit 3.0.1 which is currently
only available on Windows 7+ for desktop graphics cards. A Linux/Android
implementation is provided by NVIDIA but only for NVIDIA Tegra K1.

This Gallium state tracker is loosely based on the VDPAU tracker and since
it uses the pipe_query interface, other drivers which expose performance
counters should be also able to expose them easily through PerfKit.

Unlike GL_AMD_performance_monitor, NVIDIA PerfKit allows to monitor
multi-passes events and the API supports different types of performance
counters (GPU, CPU, OpenGL).

Currently, only MP counters for NVC0:NVE4 Nouveau drivers are exposed.

To be able to use NVIDIA PerfKit from your OpenGL applications, you will
need to install the wrapper library which includes the headers of the API.

You can download this library from:
http://cgit.freedesktop.org/~hakzsam/libperfkit/

Signed-off-by: Samuel Pitoiset 
---
 configure.ac   |  30 ++
 src/gallium/Makefile.am|   4 +
 src/gallium/state_trackers/perfkit/Makefile.am |  41 ++
 .../state_trackers/perfkit/Makefile.sources|   8 +
 src/gallium/state_trackers/perfkit/context.c   | 186 
 src/gallium/state_trackers/perfkit/counter.c   | 522 +
 src/gallium/state_trackers/perfkit/device.c|  91 
 src/gallium/state_trackers/perfkit/entrypoint.c|  78 +++
 src/gallium/state_trackers/perfkit/monitoring.c| 360 ++
 .../state_trackers/perfkit/perfkit_private.h   | 145 ++
 src/gallium/state_trackers/perfkit/util.c  |  56 +++
 src/gallium/targets/dri-perfkit.dyn|   3 +
 src/gallium/targets/perfkit/Makefile.am| 123 +
 src/gallium/targets/perfkit/perfkit.sym|   7 +
 src/gallium/targets/perfkit/target.c   |   1 +
 15 files changed, 1655 insertions(+)
 create mode 100644 src/gallium/state_trackers/perfkit/Makefile.am
 create mode 100644 src/gallium/state_trackers/perfkit/Makefile.sources
 create mode 100644 src/gallium/state_trackers/perfkit/context.c
 create mode 100644 src/gallium/state_trackers/perfkit/counter.c
 create mode 100644 src/gallium/state_trackers/perfkit/device.c
 create mode 100644 src/gallium/state_trackers/perfkit/entrypoint.c
 create mode 100644 src/gallium/state_trackers/perfkit/monitoring.c
 create mode 100644 src/gallium/state_trackers/perfkit/perfkit_private.h
 create mode 100644 src/gallium/state_trackers/perfkit/util.c
 create mode 100644 src/gallium/targets/dri-perfkit.dyn
 create mode 100644 src/gallium/targets/perfkit/Makefile.am
 create mode 100644 src/gallium/targets/perfkit/perfkit.sym
 create mode 100644 src/gallium/targets/perfkit/target.c

diff --git a/configure.ac b/configure.ac
index d32aa24..6c7aa03 100644
--- a/configure.ac
+++ b/configure.ac
@@ -79,6 +79,7 @@ LIBUDEV_REQUIRED=151
 GLPROTO_REQUIRED=1.4.14
 LIBOMXIL_BELLAGIO_REQUIRED=0.0
 LIBVA_REQUIRED=0.35.0
+PERFKIT_REQUIRED=3.0
 VDPAU_REQUIRED=0.4.1
 WAYLAND_REQUIRED=1.2.0
 XCB_REQUIRED=1.9.3
@@ -790,6 +791,11 @@ AC_ARG_ENABLE([vdpau],
  [enable vdpau library @<:@default=auto@:>@])],
[enable_vdpau="$enableval"],
[enable_vdpau=auto])
+AC_ARG_ENABLE([perfkit],
+   [AS_HELP_STRING([--enable-perfkit],
+ [enable perfkit library @<:@default=auto@:>@])],
+   [enable_perfkit="$enableval"],
+   [enable_perfkit=auto])
 AC_ARG_ENABLE([omx],
[AS_HELP_STRING([--enable-omx],
  [enable OpenMAX library @<:@default=disabled@:>@])],
@@ -856,6 +862,7 @@ if test "x$enable_opengl" = xno -a \
 "x$enable_xa" = xno -a \
 "x$enable_xvmc" = xno -a \
 "x$enable_vdpau" = xno -a \
+"x$enable_perfkit" = xno -a \
 "x$enable_omx" = xno -a \
 "x$enable_va" = xno -a \
 "x$enable_opencl" = xno; then
@@ -1584,6 +1591,10 @@ if test -n "$with_gallium_drivers" -a 
"x$with_gallium_drivers" != xswrast; then
PKG_CHECK_EXISTS([vdpau >= $VDPAU_REQUIRED], [enable_vdpau=yes], 
[enable_vdpau=no])
 fi
 
+if test "x$enable_perfkit" = xauto; then
+   PKG_CHECK_EXISTS([perfkit], [enable_perfkit=yes], [enable_perfkit=no])
+fi
+
 if test "x$enable_omx" = xauto; then
PKG_CHECK_EXISTS([libomxil-bellagio >= $LIBOMXIL_BELLAGIO_REQUIRED], 
[enable_omx=yes], [enable_omx=no])
 fi
@@ -1623,6 +1634,12 @@ if test "x$enable_vdpau" = xyes; then
 fi
 AM_CONDITIONAL(HAVE_ST_VDPAU, test "x$enable_vdpau" = xyes)
 
+if test "x$enable_perfkit" = xyes; then
+PKG_CHECK_MODULES([PERFKIT], [perfkit >= $PERFKIT_REQUIRED])
+enable_gallium_loader=$enable_shared_pipe_drivers
+fi
+AM_CONDITIONAL(HAVE_ST_PERFKIT, test "x$enable_perfkit" = xyes)
+
 if test "x$enable_omx" = xyes; then
 PKG_

[Nouveau] [RFC 2/3] util: add LIST_MOVE_TAIL to list.h

2015-06-02 Thread Samuel Pitoiset
Signed-off-by: Samuel Pitoiset 
---
 src/util/list.h | 9 +
 1 file changed, 9 insertions(+)

diff --git a/src/util/list.h b/src/util/list.h
index fb566f5..c782ef5 100644
--- a/src/util/list.h
+++ b/src/util/list.h
@@ -116,12 +116,21 @@ static inline void list_validate(struct list_head *list)
   assert(node->next->prev == node && node->prev->next == node);
 }
 
+static inline void list_move_tail(struct list_head *list,
+  struct list_head *head)
+{
+list->next->prev = list->prev;
+list->prev->next = list->next;
+list_addtail(list, head);
+}
+
 #define LIST_INITHEAD(__item) list_inithead(__item)
 #define LIST_ADD(__item, __list) list_add(__item, __list)
 #define LIST_ADDTAIL(__item, __list) list_addtail(__item, __list)
 #define LIST_REPLACE(__from, __to) list_replace(__from, __to)
 #define LIST_DEL(__item) list_del(__item)
 #define LIST_DELINIT(__item) list_delinit(__item)
+#define LIST_MOVE_TAIL(__list, __head) list_move_tail(__list, __head)
 
 #define LIST_ENTRY(__type, __item, __field)   \
 ((__type *)(((char *)(__item)) - offsetof(__type, __field)))
-- 
2.4.2

___
Nouveau mailing list
Nouveau@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/nouveau


Re: [Nouveau] [PATCH] fix a wrong use of a logical operator in drmmode_output_dpms()

2015-05-27 Thread Samuel Pitoiset



On 05/21/2015 06:40 AM, Dave Airlie wrote:

On 21 May 2015 at 03:26, Samuel Pitoiset  wrote:


On 05/20/2015 07:13 PM, Ilia Mirkin wrote:

This is obviously a bug, but one that has been there for some time.
Please figure out what this is guarding, and confirm that the feature
continues to work.


Sure, but do you have any ideas how to test this part of the DDX ?
It's the first time I play with it...


It's fine, the code just avoids going into the name checks if the type
isn't a enum,
it won't break anything actually fixing it.

The fix is

Reviewed-by: Dave Airlie 


Okay, thanks Dave.
___
Nouveau mailing list
Nouveau@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/nouveau


Re: [Nouveau] [PATCH 8/8] acpi: Use booleans when probing different _DSM types

2015-05-26 Thread Samuel Pitoiset



On 05/26/2015 02:46 PM, Pierre Moreau wrote:

I'm thinking of re-writing this patch to just OR the different returned retval 
and test for individual bits directly in the final conditionals.
So this would give something like:


int retval = 0;

while ((pdev = pci_get_class(PCI_CLASS_DISPLAY_VGA << 8, pdev)) != NULL) {
vga_count++;
retval |= nouveau_dsm_pci_probe(pdev);
}
while ((pdev = pci_get_class(PCI_CLASS_DISPLAY_3D << 8, pdev)) != NULL) {
vga_count++;
retval |= nouveau_dsm_pci_probe(pdev);
}

if (retval & NOUVEAU_DSM_HAS_OPT) {
acpi_get_name(nouveau_dsm_priv.dhandle, ACPI_FULL_PATHNAME,
&buffer);
printk(KERN_INFO "VGA switcheroo: detected Optimus DSM method %s 
handle\n",
acpi_method_name);
nouveau_dsm_priv.optimus_detected = true;
ret = true;
} else if (vga_count == 2 && (retval & NOUVEAU_DSM_HAS_MUX) && guid_valid) {
acpi_get_name(nouveau_dsm_priv.dhandle, ACPI_FULL_PATHNAME,
&buffer);
printk(KERN_INFO "VGA switcheroo: detected mux DSM switching method %s 
handle\n",
acpi_method_name);
nouveau_dsm_priv.mux_detected = true;
ret = true;
} else if (retval & NOUVEAU_DSM_HAS_GMUX) {
acpi_get_name(nouveau_dsm_priv.dhandle, ACPI_FULL_PATHNAME,
&buffer);
printk(KERN_INFO "VGA switcheroo: detected gmux DSM switching method %s 
handle\n",
acpi_method_name);
nouveau_dsm_priv.gmux_detected = true;
ret = true;
}


Any opinions on this?


If this improves readability of the code, go ahead.



Pierre

- Mail original -

Signed-off-by: Pierre Moreau 
---
  drm/nouveau/nouveau_acpi.c | 14 +++---
  1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/drm/nouveau/nouveau_acpi.c b/drm/nouveau/nouveau_acpi.c
index 3d6a1ea..5d63621 100644
--- a/drm/nouveau/nouveau_acpi.c
+++ b/drm/nouveau/nouveau_acpi.c
@@ -297,8 +297,8 @@ static bool nouveau_dsm_detect(void)
char acpi_method_name[255] = { 0 };
struct acpi_buffer buffer = {sizeof(acpi_method_name),
acpi_method_name};
struct pci_dev *pdev = NULL;
-   int has_dsm = 0;
-   int has_optimus = 0;
+   bool has_mux = false;
+   bool has_optimus = false;
bool has_gmux = false;
int vga_count = 0;
bool guid_valid;
@@ -317,9 +317,9 @@ static bool nouveau_dsm_detect(void)
  
  		retval = nouveau_dsm_pci_probe(pdev);

if (retval & NOUVEAU_DSM_HAS_MUX)
-   has_dsm |= 1;
+   has_mux = true;
if (retval & NOUVEAU_DSM_HAS_OPT)
-   has_optimus = 1;
+   has_optimus = true;
if (retval & NOUVEAU_DSM_HAS_GMUX)
has_gmux = true;
}
@@ -329,9 +329,9 @@ static bool nouveau_dsm_detect(void)
  
  		retval = nouveau_dsm_pci_probe(pdev);

if (retval & NOUVEAU_DSM_HAS_MUX)
-   has_dsm |= 1;
+   has_mux = true;
if (retval & NOUVEAU_DSM_HAS_OPT)
-   has_optimus = 1;
+   has_optimus = true;
if (retval & NOUVEAU_DSM_HAS_GMUX)
has_gmux = true;
}
@@ -344,7 +344,7 @@ static bool nouveau_dsm_detect(void)
acpi_method_name);
nouveau_dsm_priv.optimus_detected = true;
ret = true;
-   } else if (vga_count == 2 && has_dsm && guid_valid) {
+   } else if (vga_count == 2 && has_mux && guid_valid) {
acpi_get_name(nouveau_dsm_priv.dhandle, ACPI_FULL_PATHNAME,
&buffer);
printk(KERN_INFO "VGA switcheroo: detected mux DSM switching
method %s handle\n",
--
2.4.1

___
dri-devel mailing list
dri-de...@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/dri-devel


___
Nouveau mailing list
Nouveau@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/nouveau


___
Nouveau mailing list
Nouveau@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/nouveau


Re: [Nouveau] [PATCH 7/8] acpi: Add support for Apple Gmux _DMS

2015-05-26 Thread Samuel Pitoiset



On 05/26/2015 12:22 AM, Pierre Moreau wrote:

Signed-off-by: Pierre Moreau 
---
  drm/nouveau/nouveau_acpi.c | 53 --
  drm/nouveau/nouveau_acpi.h |  2 ++
  drm/nouveau/nouveau_drm.c  |  6 --
  drm/nouveau/nouveau_vga.c  | 10 +
  4 files changed, 63 insertions(+), 8 deletions(-)

diff --git a/drm/nouveau/nouveau_acpi.c b/drm/nouveau/nouveau_acpi.c
index 104d291..3d6a1ea 100644
--- a/drm/nouveau/nouveau_acpi.c
+++ b/drm/nouveau/nouveau_acpi.c
@@ -29,6 +29,10 @@
  
  #define NOUVEAU_DSM_OPTIMUS_SET_POWERDOWN (NOUVEAU_DSM_OPTIMUS_POWERDOWN_PS3 | NOUVEAU_DSM_OPTIMUS_FLAGS_CHANGED)
  
+#define NOUVEAU_DSM_GMUX_V1_CAPS (3 << 6)

+
+#define NOUVEAU_DSM_GMUX_V2_CAPS (1 << 1)
+
  /* result of the optimus caps function */
  #define OPTIMUS_ENABLED (1 << 0)
  #define OPTIMUS_STATUS_MASK (3 << 3)
@@ -45,6 +49,7 @@
  static struct nouveau_dsm_priv {
bool mux_detected;
bool optimus_detected;
+   bool gmux_detected;
acpi_handle dhandle;
acpi_handle rom_handle;
  } nouveau_dsm_priv;
@@ -57,8 +62,13 @@ bool nouveau_has_mux(void) {
return nouveau_dsm_priv.mux_detected;
  }
  
+bool nouveau_has_gmux(void) {

+   return nouveau_dsm_priv.gmux_detected;
+}
+
  #define NOUVEAU_DSM_HAS_MUX 0x1
  #define NOUVEAU_DSM_HAS_OPT 0x2
+#define NOUVEAU_DSM_HAS_GMUX 0x4
  
  #ifdef CONFIG_VGA_SWITCHEROO

  static const uint32_t nouveau_mux_dsm_rid = 0x0102;
@@ -73,6 +83,18 @@ static const char nouveau_op_dsm_muid[] = {
0xA7, 0x2B, 0x60, 0x42, 0xA6, 0xB5, 0xBE, 0xE0,
  };
  
+static const uint32_t nouveau_gmux_v1_dsm_rid = 0x101;

+static const char nouveau_gmux_v1_dsm_muid[] = {
+   0xA6, 0x69, 0x86, 0x99, 0xE9, 0x8B, 0xFB, 0x49,
+   0xBD, 0xDB, 0x51, 0xA1, 0xEF, 0xE1, 0x9C, 0x3D,
+};
+
+static const uint32_t nouveau_gmux_v2_dsm_rid = 0x001;
+static const char nouveau_gmux_v2_dsm_muid[] = {
+   0xC6, 0xB7, 0xB5, 0xA0, 0x18, 0x13, 0x1C, 0x44,
+   0xB0, 0xC9, 0xFE, 0x69, 0x5E, 0xAF, 0x94, 0x9B,
+};
+
  static int nouveau_evaluate_optimus_dsm(acpi_handle handle, int func, int 
arg, uint32_t *result)
  {
int i;
@@ -161,6 +183,17 @@ static int nouveau_evaluate_mux_dsm(acpi_handle handle, 
int func, int arg)
return ret;
  }
  
+static int nouveau_check_gmux_dsm(acpi_handle handle)

+{
+   bool has_v1 = acpi_check_dsm(handle, nouveau_gmux_v1_dsm_muid,
+nouveau_gmux_v1_dsm_rid,
+NOUVEAU_DSM_GMUX_V1_CAPS);
+   bool has_v2 = acpi_check_dsm(handle, nouveau_gmux_v2_dsm_muid,
+nouveau_gmux_v2_dsm_rid,
+NOUVEAU_DSM_GMUX_V2_CAPS);
+   return has_v1 || has_v2;
+}
+
  static int nouveau_dsm_switch_mux(acpi_handle handle, int mux_id)
  {
mxm_wmi_call_mxmx(mux_id == NOUVEAU_DSM_MUX_LED_STAMINA ? 
MXM_MXDS_ADAPTER_IGD : MXM_MXDS_ADAPTER_0);
@@ -238,6 +271,9 @@ static int nouveau_dsm_pci_probe(struct pci_dev *pdev)
   1 << NOUVEAU_DSM_MUX_POWER))
retval |= NOUVEAU_DSM_HAS_MUX;
  
+	if (nouveau_check_gmux_dsm(dhandle))

+   retval |= NOUVEAU_DSM_HAS_GMUX;
+
if (nouveau_check_optimus_dsm(dhandle))
retval |= NOUVEAU_DSM_HAS_OPT;
  
@@ -263,6 +299,7 @@ static bool nouveau_dsm_detect(void)

struct pci_dev *pdev = NULL;
int has_dsm = 0;
int has_optimus = 0;
+   bool has_gmux = false;
int vga_count = 0;
bool guid_valid;
int retval;
@@ -283,6 +320,8 @@ static bool nouveau_dsm_detect(void)
has_dsm |= 1;
if (retval & NOUVEAU_DSM_HAS_OPT)
has_optimus = 1;
+   if (retval & NOUVEAU_DSM_HAS_GMUX)
+   has_gmux = true;
}
  
  	while ((pdev = pci_get_class(PCI_CLASS_DISPLAY_3D << 8, pdev)) != NULL) {

@@ -293,9 +332,11 @@ static bool nouveau_dsm_detect(void)
has_dsm |= 1;
if (retval & NOUVEAU_DSM_HAS_OPT)
has_optimus = 1;
+   if (retval & NOUVEAU_DSM_HAS_GMUX)
+   has_gmux = true;
}
  
-	/* find the optimus DSM or the mux DSM */

+   /* find the optimus DSM, the mux DSM or the gmux DSM */
if (has_optimus == 1) {
acpi_get_name(nouveau_dsm_priv.dhandle, ACPI_FULL_PATHNAME,
&buffer);
@@ -310,6 +351,13 @@ static bool nouveau_dsm_detect(void)
acpi_method_name);
nouveau_dsm_priv.mux_detected = true;
ret = true;
+   } else if (has_gmux) {
+   acpi_get_name(nouveau_dsm_priv.dhandle, ACPI_FULL_PATHNAME,
+   &buffer);
+   printk(KERN_INFO "VGA switcheroo: detected gmux DSM switching method 
%s handle\n",
+   acpi_method_name);
+   nouveau_dsm_priv.gmux_dete

Re: [Nouveau] [PATCH 5/8] acpi: Check returned object type by Optimus _DSM locally

2015-05-26 Thread Samuel Pitoiset



On 05/26/2015 12:22 AM, Pierre Moreau wrote:

Most _DSM will return an integer value of 0x8002 when given an unknown
UUID, revision ID or function ID. Checking locally allows us to differentiate
that case from other ACPI errors, and to not report a "failed to evaluate _DSM"
if 0x8002 is returned which was confusing.

Signed-off-by: Pierre Moreau 
---
  drm/nouveau/nouveau_acpi.c | 15 ---
  1 file changed, 12 insertions(+), 3 deletions(-)

diff --git a/drm/nouveau/nouveau_acpi.c b/drm/nouveau/nouveau_acpi.c
index 073f7d7..7aeaf7d 100644
--- a/drm/nouveau/nouveau_acpi.c
+++ b/drm/nouveau/nouveau_acpi.c
@@ -88,12 +88,12 @@ static int nouveau_evaluate_optimus_dsm(acpi_handle handle, 
int func, int arg, u
for (i = 0; i < 4; i++)
args_buff[i] = (arg >> i * 8) & 0xFF;
  
-	obj = acpi_evaluate_dsm_typed(handle, nouveau_op_dsm_muid, nouveau_op_dsm_rid,

- func, &argv4, ACPI_TYPE_BUFFER);
+   obj = acpi_evaluate_dsm(handle, nouveau_op_dsm_muid, nouveau_op_dsm_rid,
+   func, &argv4);
if (!obj) {
acpi_handle_info(handle, "failed to evaluate _DSM\n");
return AE_ERROR;
-   } else {
+   } else if (obj->type == ACPI_TYPE_BUFFER) {
if (!result && obj->buffer.length == 4) {
*result  = obj->buffer.pointer[0];
*result |= (obj->buffer.pointer[1] << 8);
@@ -101,6 +101,15 @@ static int nouveau_evaluate_optimus_dsm(acpi_handle 
handle, int func, int arg, u
*result |= (obj->buffer.pointer[3] << 24);
}
ACPI_FREE(obj);
+   } else if (obj->type == ACPI_TYPE_INTEGER &&
+  obj->integer.value == 0x8002) {
+   acpi_handle_debug(handle, "failed to query Optimus _DSM\n");
+   ACPI_FREE(obj);
+   return -ENODEV;
+   } else {
+   acpi_handle_err(handle, "unexpected returned value by Optimus 
_DSM\n");
+   ACPI_FREE(obj);
+   return AE_ERROR;
}
  
  	return 0;


How do you handle the case where result is NULL and the type is 
ACPI_TYPE_BUFFER ?

Because you don't return any error. Is that expected?
___
Nouveau mailing list
Nouveau@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/nouveau


Re: [Nouveau] [PATCH 4/8] acpi: Allow evaluate_optimus_dsm to take NULL results

2015-05-26 Thread Samuel Pitoiset



On 05/26/2015 12:22 AM, Pierre Moreau wrote:

Signed-off-by: Pierre Moreau 
---
  drm/nouveau/nouveau_acpi.c | 10 --
  1 file changed, 4 insertions(+), 6 deletions(-)

diff --git a/drm/nouveau/nouveau_acpi.c b/drm/nouveau/nouveau_acpi.c
index 36f4a40..073f7d7 100644
--- a/drm/nouveau/nouveau_acpi.c
+++ b/drm/nouveau/nouveau_acpi.c
@@ -88,15 +88,14 @@ static int nouveau_evaluate_optimus_dsm(acpi_handle handle, 
int func, int arg, u
for (i = 0; i < 4; i++)
args_buff[i] = (arg >> i * 8) & 0xFF;
  
-	*result = 0;

obj = acpi_evaluate_dsm_typed(handle, nouveau_op_dsm_muid, 
nouveau_op_dsm_rid,
  func, &argv4, ACPI_TYPE_BUFFER);
if (!obj) {
acpi_handle_info(handle, "failed to evaluate _DSM\n");
return AE_ERROR;
} else {
-   if (obj->buffer.length == 4) {
-   *result |= obj->buffer.pointer[0];
+   if (!result && obj->buffer.length == 4) {
+   *result  = obj->buffer.pointer[0];


segfault here if result is NULL! ;)


*result |= (obj->buffer.pointer[1] << 8);
*result |= (obj->buffer.pointer[2] << 16);
*result |= (obj->buffer.pointer[3] << 24);
@@ -322,18 +321,17 @@ void nouveau_register_dsm_handler(void)
  /* Must be called for Optimus models before the card can be turned off */
  void nouveau_switcheroo_optimus_dsm(void)
  {
-   u32 result = 0;
if (!nouveau_dsm_priv.optimus_detected)
return;
  
  	nouveau_evaluate_optimus_dsm(nouveau_dsm_priv.dhandle,

 NOUVEAU_DSM_OPTIMUS_FLAGS,
-0x3, &result);
+0x3, NULL);
  
  	nouveau_evaluate_optimus_dsm(nouveau_dsm_priv.dhandle,

 NOUVEAU_DSM_OPTIMUS_CAPS,
 NOUVEAU_DSM_OPTIMUS_SET_POWERDOWN,
-&result);
+NULL);
  
  }
  


___
Nouveau mailing list
Nouveau@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/nouveau


Re: [Nouveau] [PATCH 2/8] acpi: Add evaluate to functons evaluating _DSM

2015-05-26 Thread Samuel Pitoiset

s/functons/functions in the commit message.

On 05/26/2015 12:22 AM, Pierre Moreau wrote:

This makes it clearer when reading the function name, as well as following the
names of the related ACPI function.

Signed-off-by: Pierre Moreau 
---
  drm/nouveau/nouveau_acpi.c | 25 ++---
  1 file changed, 14 insertions(+), 11 deletions(-)

diff --git a/drm/nouveau/nouveau_acpi.c b/drm/nouveau/nouveau_acpi.c
index 4a48e21..1f18018 100644
--- a/drm/nouveau/nouveau_acpi.c
+++ b/drm/nouveau/nouveau_acpi.c
@@ -71,7 +71,7 @@ static const char nouveau_op_dsm_muid[] = {
0xA7, 0x2B, 0x60, 0x42, 0xA6, 0xB5, 0xBE, 0xE0,
  };
  
-static int nouveau_optimus_dsm(acpi_handle handle, int func, int arg, uint32_t *result)

+static int nouveau_evaluate_optimus_dsm(acpi_handle handle, int func, int arg, 
uint32_t *result)
  {
int i;
union acpi_object *obj;
@@ -118,7 +118,7 @@ static int nouveau_check_optimus_dsm(acpi_handle handle)
 * Function 0 returns a Buffer containing available functions.
 * The args parameter is ignored for function 0, so just put 0 in it
 */
-   if (nouveau_optimus_dsm(handle, 0, 0, &result))
+   if (nouveau_evaluate_optimus_dsm(handle, 0, 0, &result))
return 0;
  
  	/*

@@ -128,7 +128,7 @@ static int nouveau_check_optimus_dsm(acpi_handle handle)
return result & 1 && result & (1 << NOUVEAU_DSM_OPTIMUS_CAPS);
  }
  
-static int nouveau_mux_dsm(acpi_handle handle, int func, int arg)

+static int nouveau_evaluate_mux_dsm(acpi_handle handle, int func, int arg)
  {
int ret = 0;
union acpi_object *obj;
@@ -155,7 +155,7 @@ static int nouveau_dsm_switch_mux(acpi_handle handle, int 
mux_id)
  {
mxm_wmi_call_mxmx(mux_id == NOUVEAU_DSM_MUX_LED_STAMINA ? 
MXM_MXDS_ADAPTER_IGD : MXM_MXDS_ADAPTER_0);
mxm_wmi_call_mxds(mux_id == NOUVEAU_DSM_MUX_LED_STAMINA ? 
MXM_MXDS_ADAPTER_IGD : MXM_MXDS_ADAPTER_0);
-   return nouveau_mux_dsm(handle, NOUVEAU_DSM_MUX_LED, mux_id);
+   return nouveau_evaluate_mux_dsm(handle, NOUVEAU_DSM_MUX_LED, mux_id);
  }
  
  static int nouveau_dsm_set_discrete_state(acpi_handle handle, enum vga_switcheroo_state state)

@@ -165,7 +165,7 @@ static int nouveau_dsm_set_discrete_state(acpi_handle 
handle, enum vga_switchero
arg = NOUVEAU_DSM_MUX_POWER_SPEED;
else
arg = NOUVEAU_DSM_MUX_POWER_STAMINA;
-   nouveau_mux_dsm(handle, NOUVEAU_DSM_MUX_POWER, arg);
+   nouveau_evaluate_mux_dsm(handle, NOUVEAU_DSM_MUX_POWER, arg);
return 0;
  }
  
@@ -233,8 +233,8 @@ static int nouveau_dsm_pci_probe(struct pci_dev *pdev)
  
  	if (retval & NOUVEAU_DSM_HAS_OPT) {

uint32_t result;
-   nouveau_optimus_dsm(dhandle, NOUVEAU_DSM_OPTIMUS_CAPS, 0,
-   &result);
+   nouveau_evaluate_optimus_dsm(dhandle, NOUVEAU_DSM_OPTIMUS_CAPS,
+0, &result);
dev_info(&pdev->dev, "optimus capabilities: %s, status %s%s\n",
 (result & OPTIMUS_ENABLED) ? "enabled" : "disabled",
 (result & OPTIMUS_DYNAMIC_PWR_CAP) ? "dynamic power, " : 
"",
@@ -324,11 +324,14 @@ void nouveau_switcheroo_optimus_dsm(void)
if (!nouveau_dsm_priv.optimus_detected)
return;
  
-	nouveau_optimus_dsm(nouveau_dsm_priv.dhandle, NOUVEAU_DSM_OPTIMUS_FLAGS,

-   0x3, &result);
+   nouveau_evaluate_optimus_dsm(nouveau_dsm_priv.dhandle,
+NOUVEAU_DSM_OPTIMUS_FLAGS,
+0x3, &result);
  
-	nouveau_optimus_dsm(nouveau_dsm_priv.dhandle, NOUVEAU_DSM_OPTIMUS_CAPS,

-   NOUVEAU_DSM_OPTIMUS_SET_POWERDOWN, &result);
+   nouveau_evaluate_optimus_dsm(nouveau_dsm_priv.dhandle,
+NOUVEAU_DSM_OPTIMUS_CAPS,
+NOUVEAU_DSM_OPTIMUS_SET_POWERDOWN,
+&result);
  
  }
  


___
Nouveau mailing list
Nouveau@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/nouveau


Re: [Nouveau] [Mesa-dev] [PATCH 2/2] nv30: fix clip plane uploads and enable changes

2015-05-24 Thread Samuel Pitoiset



On 05/24/2015 06:58 AM, Ilia Mirkin wrote:

nv30_validate_clip depends on the rasterizer state. Also we should
upload all the new clip planes on change since next time the plane data
won't have changed, but the enables might.

Signed-off-by: Ilia Mirkin 
---
  src/gallium/drivers/nouveau/nv30/nv30_state_validate.c | 16 +++-
  1 file changed, 7 insertions(+), 9 deletions(-)

diff --git a/src/gallium/drivers/nouveau/nv30/nv30_state_validate.c 
b/src/gallium/drivers/nouveau/nv30/nv30_state_validate.c
index 86ac4f7..a954dcc 100644
--- a/src/gallium/drivers/nouveau/nv30/nv30_state_validate.c
+++ b/src/gallium/drivers/nouveau/nv30/nv30_state_validate.c
@@ -272,15 +272,13 @@ nv30_validate_clip(struct nv30_context *nv30)
 uint32_t clpd_enable = 0;
  
 for (i = 0; i < 6; i++) {

-  if (nv30->rast->pipe.clip_plane_enable & (1 << i)) {
- if (nv30->dirty & NV30_NEW_CLIP) {
-BEGIN_NV04(push, NV30_3D(VP_UPLOAD_CONST_ID), 5);
-PUSH_DATA (push, i);
-PUSH_DATAp(push, nv30->clip.ucp[i], 4);
- }
-
- clpd_enable |= 1 << (1 + 4*i);
+  if (nv30->dirty & NV30_NEW_CLIP) {
+ BEGIN_NV04(push, NV30_3D(VP_UPLOAD_CONST_ID), 5);
+ PUSH_DATA (push, i);
+ PUSH_DATAp(push, nv30->clip.ucp[i], 4);
}
+  if (nv30->rast->pipe.clip_plane_enable & (1 << i))
+ clpd_enable |= 2 << (4*i);


Can you explain why did you change this line?


 }
  
 BEGIN_NV04(push, NV30_3D(VP_CLIP_PLANES_ENABLE), 1);

@@ -389,7 +387,7 @@ static struct state_validate hwtnl_validate_list[] = {
  { nv30_validate_stipple,   NV30_NEW_STIPPLE },
  { nv30_validate_scissor,   NV30_NEW_SCISSOR | NV30_NEW_RASTERIZER },
  { nv30_validate_viewport,  NV30_NEW_VIEWPORT },
-{ nv30_validate_clip,  NV30_NEW_CLIP },
+{ nv30_validate_clip,  NV30_NEW_CLIP | NV30_NEW_RASTERIZER },
  { nv30_fragprog_validate,  NV30_NEW_FRAGPROG | NV30_NEW_FRAGCONST },
  { nv30_vertprog_validate,  NV30_NEW_VERTPROG | NV30_NEW_VERTCONST |
 NV30_NEW_FRAGPROG | NV30_NEW_RASTERIZER },


___
Nouveau mailing list
Nouveau@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/nouveau


Re: [Nouveau] [PATCH] fix a wrong use of a logical operator in drmmode_output_dpms()

2015-05-20 Thread Samuel Pitoiset



On 05/20/2015 07:13 PM, Ilia Mirkin wrote:

This is obviously a bug, but one that has been there for some time.
Please figure out what this is guarding, and confirm that the feature
continues to work.


Sure, but do you have any ideas how to test this part of the DDX ?
It's the first time I play with it...



On Wed, May 20, 2015 at 1:11 PM, Tobias Klausmann
 wrote:

looks good to me! :)

Feel free to add my R-b.

On 20.05.2015 17:08, Samuel Pitoiset wrote:

This is probably a typo error which has been introduced in 2009...
This fixes the following warning detected by Clang :

drmmode_display.c:907:30: warning: use of logical '&&' with constant
operand [-Wconstant-logical-operand]
  if (props && (props->flags && DRM_MODE_PROP_ENUM)) {

Signed-off-by: Samuel Pitoiset 
---
   src/drmmode_display.c | 2 +-
   1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/drmmode_display.c b/src/drmmode_display.c
index 7c1d2bb..161bccd 100644
--- a/src/drmmode_display.c
+++ b/src/drmmode_display.c
@@ -904,7 +904,7 @@ drmmode_output_dpms(xf86OutputPtr output, int mode)
 for (i = 0; i < koutput->count_props; i++) {
 props = drmModeGetProperty(drmmode->fd,
koutput->props[i]);
-   if (props && (props->flags && DRM_MODE_PROP_ENUM)) {
+   if (props && (props->flags & DRM_MODE_PROP_ENUM)) {
 if (!strcmp(props->name, "DPMS")) {
 mode_id = koutput->props[i];
 drmModeFreeProperty(props);


___
Nouveau mailing list
Nouveau@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/nouveau


___
Nouveau mailing list
Nouveau@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/nouveau


[Nouveau] [PATCH] fix a wrong use of a logical operator in drmmode_output_dpms()

2015-05-20 Thread Samuel Pitoiset
This is probably a typo error which has been introduced in 2009...
This fixes the following warning detected by Clang :

drmmode_display.c:907:30: warning: use of logical '&&' with constant operand 
[-Wconstant-logical-operand]
if (props && (props->flags && DRM_MODE_PROP_ENUM)) {

Signed-off-by: Samuel Pitoiset 
---
 src/drmmode_display.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/drmmode_display.c b/src/drmmode_display.c
index 7c1d2bb..161bccd 100644
--- a/src/drmmode_display.c
+++ b/src/drmmode_display.c
@@ -904,7 +904,7 @@ drmmode_output_dpms(xf86OutputPtr output, int mode)
 
for (i = 0; i < koutput->count_props; i++) {
props = drmModeGetProperty(drmmode->fd, koutput->props[i]);
-   if (props && (props->flags && DRM_MODE_PROP_ENUM)) {
+   if (props && (props->flags & DRM_MODE_PROP_ENUM)) {
if (!strcmp(props->name, "DPMS")) {
mode_id = koutput->props[i];
drmModeFreeProperty(props);
-- 
2.4.1

___
Nouveau mailing list
Nouveau@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/nouveau


Re: [Nouveau] [PATCH 2/2] pm: fix a potential race condition when creating an engine context

2015-05-10 Thread Samuel Pitoiset

* bump *

Ben, could you take a look at the series ?

On 04/14/2015 10:43 PM, Samuel Pitoiset wrote:

There is always the possiblity that the ppm->context pointer would get
partially updated and accidentally would equal ctx. This would allow two
contexts to co-exist, which is not acceptable. Moving the test to the
critical section takes care of this problem.

Signed-off-by: Samuel Pitoiset 
Signed-off-by: Martin Peres 
---
  drm/nouveau/nvkm/engine/pm/base.c | 7 +++
  1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/drm/nouveau/nvkm/engine/pm/base.c 
b/drm/nouveau/nvkm/engine/pm/base.c
index 274457c..4cf36a3 100644
--- a/drm/nouveau/nvkm/engine/pm/base.c
+++ b/drm/nouveau/nvkm/engine/pm/base.c
@@ -358,12 +358,11 @@ nvkm_perfctx_ctor(struct nvkm_object *parent, struct 
nvkm_object *engine,
mutex_lock(&nv_subdev(ppm)->mutex);
if (ppm->context == NULL)
ppm->context = ctx;
-   mutex_unlock(&nv_subdev(ppm)->mutex);
-
if (ctx != ppm->context)
-   return -EBUSY;
+   ret = -EBUSY;
+   mutex_unlock(&nv_subdev(ppm)->mutex);
  
-	return 0;

+   return ret;
  }
  
  struct nvkm_oclass


___
Nouveau mailing list
Nouveau@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/nouveau


[Nouveau] [PATCH 1/2] pm: prevent freeing the wrong engine context

2015-04-14 Thread Samuel Pitoiset
This fixes a crash when multiple PM engine contexts are created.

Signed-off-by: Samuel Pitoiset 
Reviewed-by: Martin Peres 
---
 drm/nouveau/nvkm/engine/pm/base.c | 7 +--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/drm/nouveau/nvkm/engine/pm/base.c 
b/drm/nouveau/nvkm/engine/pm/base.c
index 2006c44..274457c 100644
--- a/drm/nouveau/nvkm/engine/pm/base.c
+++ b/drm/nouveau/nvkm/engine/pm/base.c
@@ -332,9 +332,12 @@ static void
 nvkm_perfctx_dtor(struct nvkm_object *object)
 {
struct nvkm_pm *ppm = (void *)object->engine;
+   struct nvkm_perfctx *ctx = (void *)object;
+
mutex_lock(&nv_subdev(ppm)->mutex);
-   nvkm_engctx_destroy(&ppm->context->base);
-   ppm->context = NULL;
+   nvkm_engctx_destroy(&ctx->base);
+   if (ppm->context == ctx)
+   ppm->context = NULL;
mutex_unlock(&nv_subdev(ppm)->mutex);
 }
 
-- 
2.3.5

___
Nouveau mailing list
Nouveau@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/nouveau


[Nouveau] [PATCH 2/2] pm: fix a potential race condition when creating an engine context

2015-04-14 Thread Samuel Pitoiset
There is always the possiblity that the ppm->context pointer would get
partially updated and accidentally would equal ctx. This would allow two
contexts to co-exist, which is not acceptable. Moving the test to the
critical section takes care of this problem.

Signed-off-by: Samuel Pitoiset 
Signed-off-by: Martin Peres 
---
 drm/nouveau/nvkm/engine/pm/base.c | 7 +++
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/drm/nouveau/nvkm/engine/pm/base.c 
b/drm/nouveau/nvkm/engine/pm/base.c
index 274457c..4cf36a3 100644
--- a/drm/nouveau/nvkm/engine/pm/base.c
+++ b/drm/nouveau/nvkm/engine/pm/base.c
@@ -358,12 +358,11 @@ nvkm_perfctx_ctor(struct nvkm_object *parent, struct 
nvkm_object *engine,
mutex_lock(&nv_subdev(ppm)->mutex);
if (ppm->context == NULL)
ppm->context = ctx;
-   mutex_unlock(&nv_subdev(ppm)->mutex);
-
if (ctx != ppm->context)
-   return -EBUSY;
+   ret = -EBUSY;
+   mutex_unlock(&nv_subdev(ppm)->mutex);
 
-   return 0;
+   return ret;
 }
 
 struct nvkm_oclass
-- 
2.3.5

___
Nouveau mailing list
Nouveau@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/nouveau


Re: [Nouveau] [Mesa-dev] [PATCH] nv50: allocate more offset space for occlusion queries

2015-04-04 Thread Samuel Pitoiset

Reviewed-by: Samuel Pitoiset 

But please, fix the comment in the nv50_query struct, now it is "/* base 
+ i * 32 */".


On 04/04/2015 06:00 AM, Ilia Mirkin wrote:

Commit 1a170980a09 started writing to q->data[4]/[5] but kept the
per-query space at 16, which meant that in some cases we would write
past the end of the buffer. Rotate by 32, like nvc0 does.

Signed-off-by: Ilia Mirkin 
Tested-by: Nick Tenney 
Cc: "10.4 10.5" 
---
  src/gallium/drivers/nouveau/nv50/nv50_query.c | 8 
  1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/src/gallium/drivers/nouveau/nv50/nv50_query.c 
b/src/gallium/drivers/nouveau/nv50/nv50_query.c
index e81ac5a..6a23de4 100644
--- a/src/gallium/drivers/nouveau/nv50/nv50_query.c
+++ b/src/gallium/drivers/nouveau/nv50/nv50_query.c
@@ -116,8 +116,8 @@ nv50_query_create(struct pipe_context *pipe, unsigned type, 
unsigned index)
 q->type = type;
  
 if (q->type == PIPE_QUERY_OCCLUSION_COUNTER) {

-  q->offset -= 16;
-  q->data -= 16 / sizeof(*q->data); /* we advance before query_begin ! */
+  q->offset -= 32;
+  q->data -= 32 / sizeof(*q->data); /* we advance before query_begin ! */
 }
  
 return (struct pipe_query *)q;

@@ -150,8 +150,8 @@ nv50_query_begin(struct pipe_context *pipe, struct 
pipe_query *pq)
  * initialized it to TRUE.
  */
 if (q->type == PIPE_QUERY_OCCLUSION_COUNTER) {
-  q->offset += 16;
-  q->data += 16 / sizeof(*q->data);
+  q->offset += 32;
+  q->data += 32 / sizeof(*q->data);
if (q->offset - q->base == NV50_QUERY_ALLOC_SPACE)
   nv50_query_allocate(nv50, q, NV50_QUERY_ALLOC_SPACE);
  


___
Nouveau mailing list
Nouveau@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/nouveau


Re: [Nouveau] [RFC PATCH 2/3] dvfs: add support for GK20A

2014-12-18 Thread Samuel Pitoiset

On 12/18/2014 11:25 AM, Ben Skeggs wrote:

On Thu, Dec 18, 2014 at 8:13 PM, Vince Hsu  wrote:

Hello Ben,

On 12/18/2014 05:34 PM, Ben Skeggs wrote:

On Thu, Dec 18, 2014 at 4:28 PM, Vince Hsu  wrote:

This patch creates a subdev for DVFS (Dynamic Voltage and Frequency
Scaling)
support in Nouveau. This subdev refers to the status information provided
by
the NVIDIA hardware and tries to adjust the performance level based on
the
calculated target. Only the GK20A is supported right now.

Hey Vince,

I'd not make a new subdev, but implement this in the PMU (PWR
currently) subdev.  The ucode that's supposed to be running there can
do the performance monitoring in a more complex implementation, and
it's PMU counters you're touching to get the usage stats :)  But the
simpler on-host implementation is totally fine.

Yeah, I know we have the counters defined in daemon.c. Martin reminded me
that Roy had a patch to remove that, sorry that I could not find the link
now. Another reason I did not use the nouveau_specsig is because I had to
create some nvif structures to access the counters and that's not
straightforward. I'm happy to hear you're fine with the on-host
implementation. :)


Hey Vince,

It's not Roy but me who had submitted a patch which removes PDAEMON 
signals. :-)


However, the patch is not ready to be upstream because we don't have any 
other ways to expose these performance counters.


Currently, I'm working on perfmon and nvif to expose hardware events to 
the userspace for NV50. I hope to submit the bunch of patches as soon as 
possible but unfortunately,

I don't have my full time on this, so it takes more time than expected.



I will move all to PWR subdev in the next version.


The current base PMU implementation tries to do a lot of stuff that
you don't need, just override the implementation entirely for GK20A
for now if that's easier than reworking it.

So currently there is no dGPU using the PMU? I just don't want to break any
dGPU functions. ;)

We upload a custom firmware to it, which we (currently) only use as a
script interpreter for memory clock changes.  But for your needs right
now, it'd be fine to ignore all the common code there for GK20A.



Aside from the subdev move, it looks good so far to me.  Glad to see
the CLK stuff isn't totally useless, despite it needing a *lot* of
work.

BTW, can we add some execution time information for pstate? I mean something
like "/sys/devices/system/cpu/cpu0/cpufreq/stats/time_in_state". I know we
don't want to change the user space ABI though.

Thanks,
Vince



Thanks,
Ben.


Signed-off-by: Vince Hsu 
---
   drm/Kbuild |   2 +
   drm/core/include/subdev/dvfs.h |   1 +
   drm/core/subdev/dvfs/base.c|   1 +
   drm/core/subdev/dvfs/gk20a.c   |   1 +
   drm/core/subdev/dvfs/priv.h|   1 +
   nvkm/engine/device/nve0.c  |   2 +
   nvkm/include/core/device.h |   1 +
   nvkm/include/subdev/dvfs.h |  30 
   nvkm/subdev/Makefile.am|   5 +-
   nvkm/subdev/dvfs/Makefile.am   |   6 ++
   nvkm/subdev/dvfs/base.c| 129 ++
   nvkm/subdev/dvfs/gk20a.c   | 156
+
   nvkm/subdev/dvfs/priv.h|  43 
   13 files changed, 376 insertions(+), 2 deletions(-)
   create mode 12 drm/core/include/subdev/dvfs.h
   create mode 12 drm/core/subdev/dvfs/base.c
   create mode 12 drm/core/subdev/dvfs/gk20a.c
   create mode 12 drm/core/subdev/dvfs/priv.h
   create mode 100644 nvkm/include/subdev/dvfs.h
   create mode 100644 nvkm/subdev/dvfs/Makefile.am
   create mode 100644 nvkm/subdev/dvfs/base.c
   create mode 100644 nvkm/subdev/dvfs/gk20a.c
   create mode 100644 nvkm/subdev/dvfs/priv.h

diff --git a/drm/Kbuild b/drm/Kbuild
index 061d9faef836..e7eb05e666a0 100644
--- a/drm/Kbuild
+++ b/drm/Kbuild
@@ -227,6 +227,8 @@ nouveau-y += core/subdev/volt/base.o
   nouveau-y += core/subdev/volt/gpio.o
   nouveau-y += core/subdev/volt/nv40.o
   nouveau-y += core/subdev/volt/gk20a.o
+nouveau-y += core/subdev/dvfs/base.o
+nouveau-y += core/subdev/dvfs/gk20a.o

   nouveau-y += core/engine/falcon.o
   nouveau-y += core/engine/xtensa.o
diff --git a/drm/core/include/subdev/dvfs.h
b/drm/core/include/subdev/dvfs.h
new file mode 12
index ..553a6968350b
--- /dev/null
+++ b/drm/core/include/subdev/dvfs.h
@@ -0,0 +1 @@
+../../../../nvkm/include/subdev/dvfs.h
\ No newline at end of file
diff --git a/drm/core/subdev/dvfs/base.c b/drm/core/subdev/dvfs/base.c
new file mode 12
index ..296334ee52d1
--- /dev/null
+++ b/drm/core/subdev/dvfs/base.c
@@ -0,0 +1 @@
+../../../../nvkm/subdev/dvfs/base.c
\ No newline at end of file
diff --git a/drm/core/subdev/dvfs/gk20a.c b/drm/core/subdev/dvfs/gk20a.c
new file mode 12
index ..d05d493e3fc9
--- /dev/null
+++ b/drm/core/subdev/dvfs/gk20a.c
@@ -0,0 +1 @@
+../../../../nvkm/subdev/dvfs/gk20a.c
\ No newline at end of file
diff --git a/drm/core/subdev/dvfs/pri

[Nouveau] [PATCH 1/3] lib: fix devices selection using -a

2014-09-15 Thread Samuel Pitoiset
Signed-off-by: Samuel Pitoiset 
---
 lib/kern.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lib/kern.c b/lib/kern.c
index 930cd35..7e8f3e9 100644
--- a/lib/kern.c
+++ b/lib/kern.c
@@ -173,7 +173,7 @@ drm_client_init(const char *name, u64 device, const char 
*cfg,
if (ret = -ENOMEM, !(drm = *ppriv = malloc(sizeof(*drm
goto fail;
 
-   for (minor = DRM_RENDER_MIN; minor <= DRM_RENDER_MAX; minor++) {
+   for (minor = DRM_RENDER_MIN + device; minor <= DRM_RENDER_MAX; minor++) 
{
snprintf(path, sizeof(path), "/dev/dri/renderD%d", minor);
if ((drm->fd = open(path, O_RDWR, 0)) < 0)
continue;
-- 
2.0.0

___
Nouveau mailing list
Nouveau@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/nouveau


[Nouveau] [PATCH 2/3] perfmon: remove unused nouveau_perfsig_wrap() function

2014-09-15 Thread Samuel Pitoiset
Signed-off-by: Samuel Pitoiset 
---
 nvkm/engine/perfmon/base.c | 20 
 nvkm/engine/perfmon/priv.h |  3 ---
 2 files changed, 23 deletions(-)

diff --git a/nvkm/engine/perfmon/base.c b/nvkm/engine/perfmon/base.c
index 5fa45e1..b74734e 100644
--- a/nvkm/engine/perfmon/base.c
+++ b/nvkm/engine/perfmon/base.c
@@ -80,26 +80,6 @@ nouveau_perfsig_find(struct nouveau_perfmon *ppm, const char 
*name, u32 size,
return nouveau_perfsig_find_(dom, name, size);
 }
 
-struct nouveau_perfctr *
-nouveau_perfsig_wrap(struct nouveau_perfmon *ppm, const char *name,
-struct nouveau_perfdom **pdom)
-{
-   struct nouveau_perfsig *sig;
-   struct nouveau_perfctr *ctr;
-
-   sig = nouveau_perfsig_find(ppm, name, strlen(name), pdom);
-   if (!sig)
-   return NULL;
-
-   ctr = kzalloc(sizeof(*ctr), GFP_KERNEL);
-   if (ctr) {
-   ctr->signal[0] = sig;
-   ctr->logic_op = 0x;
-   }
-
-   return ctr;
-}
-
 
/***
  * Perfmon object classes
  
**/
diff --git a/nvkm/engine/perfmon/priv.h b/nvkm/engine/perfmon/priv.h
index 0ac8714..9e27ff5 100644
--- a/nvkm/engine/perfmon/priv.h
+++ b/nvkm/engine/perfmon/priv.h
@@ -31,9 +31,6 @@ struct nouveau_perfsig {
 };
 
 struct nouveau_perfdom;
-struct nouveau_perfctr *
-nouveau_perfsig_wrap(struct nouveau_perfmon *, const char *,
-struct nouveau_perfdom **);
 
 struct nouveau_specdom {
u16 signal_nr;
-- 
2.0.0

___
Nouveau mailing list
Nouveau@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/nouveau


[Nouveau] Prepare the way for performance counters in perfmon

2014-09-15 Thread Samuel Pitoiset
Hi folks,

This set of patches is just for clearing the way before introducing
the infrastructure for performance counters in perfmon.

I'll try to publish a new version of my kernel interface based on nvif
in a couple of days.

See you.

___
Nouveau mailing list
Nouveau@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/nouveau


[Nouveau] [PATCH 3/3] perfmon: remove PDAEMON signals

2014-09-15 Thread Samuel Pitoiset
As discussed with Martin Peres, PDAEMON signals should be exposed
through sysfs and not managed by the perfmon engine which is only
used for performance counters.

Signed-off-by: Samuel Pitoiset 
---
 drm/Kbuild   |   1 -
 drm/core/engine/perfmon/daemon.c |   1 -
 nvkm/engine/perfmon/Makefile.am  |   1 -
 nvkm/engine/perfmon/daemon.c | 109 ---
 nvkm/engine/perfmon/nva3.c   |  20 +--
 nvkm/engine/perfmon/nvc0.c   |   6 ---
 nvkm/engine/perfmon/nve0.c   |   7 ---
 nvkm/engine/perfmon/nvf0.c   |   5 --
 nvkm/engine/perfmon/priv.h   |   4 --
 nvkm/include/engine/perfmon.h|   4 --
 10 files changed, 1 insertion(+), 157 deletions(-)
 delete mode 12 drm/core/engine/perfmon/daemon.c
 delete mode 100644 nvkm/engine/perfmon/daemon.c

diff --git a/drm/Kbuild b/drm/Kbuild
index 949a034..b63c0ed 100644
--- a/drm/Kbuild
+++ b/drm/Kbuild
@@ -319,7 +319,6 @@ nouveau-y += core/engine/mpeg/nv44.o
 nouveau-y += core/engine/mpeg/nv50.o
 nouveau-y += core/engine/mpeg/nv84.o
 nouveau-y += core/engine/perfmon/base.o
-nouveau-y += core/engine/perfmon/daemon.o
 nouveau-y += core/engine/perfmon/nv40.o
 nouveau-y += core/engine/perfmon/nv50.o
 nouveau-y += core/engine/perfmon/nv84.o
diff --git a/drm/core/engine/perfmon/daemon.c b/drm/core/engine/perfmon/daemon.c
deleted file mode 12
index 3351142..000
--- a/drm/core/engine/perfmon/daemon.c
+++ /dev/null
@@ -1 +0,0 @@
-../../../../nvkm/engine/perfmon/daemon.c
\ No newline at end of file
diff --git a/nvkm/engine/perfmon/Makefile.am b/nvkm/engine/perfmon/Makefile.am
index f6e2279..48e3801 100644
--- a/nvkm/engine/perfmon/Makefile.am
+++ b/nvkm/engine/perfmon/Makefile.am
@@ -1,7 +1,6 @@
 noinst_LTLIBRARIES = libperfmon.la
 
 libperfmon_la_SOURCES = base.c \
-   daemon.c \
nv40.c \
nv50.c \
nv84.c \
diff --git a/nvkm/engine/perfmon/daemon.c b/nvkm/engine/perfmon/daemon.c
deleted file mode 100644
index 50696cc..000
--- a/nvkm/engine/perfmon/daemon.c
+++ /dev/null
@@ -1,109 +0,0 @@
-/*
- * Copyright 2013 Red Hat Inc.
- *
- * 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 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
- * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) 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.
- *
- * Authors: Ben Skeggs
- */
-
-#include "priv.h"
-
-static void
-pwr_perfctr_init(struct nouveau_perfmon *ppm, struct nouveau_perfdom *dom,
-struct nouveau_perfctr *ctr)
-{
-   u32 mask = 0x;
-   u32 ctrl = 0x0001;
-   int i;
-
-   for (i = 0; i < ARRAY_SIZE(ctr->signal) && ctr->signal[i]; i++)
-   mask |= 1 << (ctr->signal[i] - dom->signal);
-
-   nv_wr32(ppm, 0x10a504 + (ctr->slot * 0x10), mask);
-   nv_wr32(ppm, 0x10a50c + (ctr->slot * 0x10), ctrl);
-   nv_wr32(ppm, 0x10a50c + (ppm->last * 0x10), 0x0003);
-}
-
-static void
-pwr_perfctr_read(struct nouveau_perfmon *ppm, struct nouveau_perfdom *dom,
-struct nouveau_perfctr *ctr)
-{
-   ctr->ctr = ppm->pwr[ctr->slot];
-   ctr->clk = ppm->pwr[ppm->last];
-}
-
-static void
-pwr_perfctr_next(struct nouveau_perfmon *ppm, struct nouveau_perfdom *dom)
-{
-   int i;
-
-   for (i = 0; i <= ppm->last; i++) {
-   ppm->pwr[i] = nv_rd32(ppm, 0x10a508 + (i * 0x10));
-   nv_wr32(ppm, 0x10a508 + (i * 0x10), 0x8000);
-   }
-}
-
-static const struct nouveau_funcdom
-pwr_perfctr_func = {
-   .init = pwr_perfctr_init,
-   .read = pwr_perfctr_read,
-   .next = pwr_perfctr_next,
-};
-
-const struct nouveau_specdom
-nva3_perfmon_pwr[] = {
-   { 0x20, (const struct nouveau_specsig[]) {
-   { 0x00, "pwr_gr_idle" },
-   { 0x04, "pwr_bsp_idle" },
-   { 0x05, "pwr_vp_idle" },
-   { 0x06, "pwr_ppp_idle" },
-   

[Nouveau] [PATCH] perfmon: do not forget to destroy the engine context

2014-07-21 Thread Samuel Pitoiset
This fixes a crash when we reload Nouveau DRM.

Signed-off-by: Samuel Pitoiset 
---
 nvkm/engine/perfmon/base.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/nvkm/engine/perfmon/base.c b/nvkm/engine/perfmon/base.c
index e9c5e51..7481003 100644
--- a/nvkm/engine/perfmon/base.c
+++ b/nvkm/engine/perfmon/base.c
@@ -303,6 +303,7 @@ nouveau_perfctx_dtor(struct nouveau_object *object)
 {
struct nouveau_perfmon *ppm = (void *)object->engine;
mutex_lock(&nv_subdev(ppm)->mutex);
+   nouveau_engctx_destroy(&ppm->context->base);
ppm->context = NULL;
mutex_unlock(&nv_subdev(ppm)->mutex);
 }
-- 
2.0.0

___
Nouveau mailing list
Nouveau@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/nouveau


<    1   2