From 6085c90f499c642bc41a646b0efbdfe60e096c74 Mon Sep 17 00:00:00 2001 From: Konsta Holtta Date: Fri, 6 Mar 2015 16:33:43 +0200 Subject: gpu: nvgpu: add per-channel refcounting Add reference counting for channels, and wait for reference count to get to 0 in gk20a_channel_free() before actually freeing the channel. Also, change free channel tracking a bit by employing a list of free channels, which simplifies the procedure of finding available channels with reference counting. Each use of a channel must have a reference taken before use or held by the caller. Taking a reference of a wild channel pointer may fail, if the channel is either not opened or in a process of being closed. Also, add safeguards for protecting accidental use of closed channels, specifically, by setting ch->g = NULL in channel free. This will make it obvious if freed channel is attempted to be used. The last user of a channel might be the deferred interrupt handler, so wait for deferred interrupts to be processed twice in the channel free procedure: once for providing last notifications to the channel and once to make sure there are no stale pointers left after referencing to the channel has been denied. Finally, fix some races in channel and TSG force reset IOCTL path, by pausing the channel scheduler in gk20a_fifo_recover_ch() and gk20a_fifo_recover_tsg(), while the affected engines have been identified, the appropriate MMU faults triggered, and the MMU faults handled. In this case, make sure that the MMU fault does not attempt to query the hardware about the failing channel or TSG ids. This should make channel recovery more safe also in the regular (i.e., not in the interrupt handler) context. Bug 1530226 Bug 1597493 Bug 1625901 Bug 200076344 Bug 200071810 Change-Id: Ib274876908e18219c64ea41e50ca443df81d957b Signed-off-by: Terje Bergstrom Signed-off-by: Konsta Holtta Signed-off-by: Sami Kiminki Reviewed-on: http://git-master/r/448463 (cherry picked from commit 3f03aeae64ef2af4829e06f5f63062e8ebd21353) Reviewed-on: http://git-master/r/755147 Reviewed-by: Automatic_Commit_Validation_User --- include/trace/events/gk20a.h | 50 ++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 46 insertions(+), 4 deletions(-) (limited to 'include/trace/events') diff --git a/include/trace/events/gk20a.h b/include/trace/events/gk20a.h index ad738f43..461ff6e8 100644 --- a/include/trace/events/gk20a.h +++ b/include/trace/events/gk20a.h @@ -140,12 +140,54 @@ DEFINE_EVENT(gk20a, gk20a_mm_g_elpg_flush_locked_done, TP_ARGS(name) ); -TRACE_EVENT(gk20a_channel_update, - TP_PROTO(const void *channel), +DECLARE_EVENT_CLASS(gk20a_channel, + TP_PROTO(int channel), TP_ARGS(channel), - TP_STRUCT__entry(__field(const void *, channel)), + TP_STRUCT__entry(__field(int, channel)), TP_fast_assign(__entry->channel = channel;), - TP_printk("channel=%p", __entry->channel) + TP_printk("ch id %d", __entry->channel) +); +DEFINE_EVENT(gk20a_channel, gk20a_channel_update, + TP_PROTO(int channel), + TP_ARGS(channel) +); +DEFINE_EVENT(gk20a_channel, gk20a_free_channel, + TP_PROTO(int channel), + TP_ARGS(channel) +); +DEFINE_EVENT(gk20a_channel, gk20a_open_new_channel, + TP_PROTO(int channel), + TP_ARGS(channel) +); +DEFINE_EVENT(gk20a_channel, gk20a_release_used_channel, + TP_PROTO(int channel), + TP_ARGS(channel) +); + +DECLARE_EVENT_CLASS(gk20a_channel_getput, + TP_PROTO(int channel, const char *caller), + TP_ARGS(channel, caller), + TP_STRUCT__entry( + __field(int, channel) + __field(const char *, caller) + ), + TP_fast_assign( + __entry->channel = channel; + __entry->caller = caller; + ), + TP_printk("channel %d caller %s", __entry->channel, __entry->caller) +); +DEFINE_EVENT(gk20a_channel_getput, gk20a_channel_get, + TP_PROTO(int channel, const char *caller), + TP_ARGS(channel, caller) +); +DEFINE_EVENT(gk20a_channel_getput, gk20a_channel_put, + TP_PROTO(int channel, const char *caller), + TP_ARGS(channel, caller) +); +DEFINE_EVENT(gk20a_channel_getput, gk20a_channel_put_nofree, + TP_PROTO(int channel, const char *caller), + TP_ARGS(channel, caller) ); TRACE_EVENT(gk20a_push_cmdbuf, -- cgit v1.2.2