All of lore.kernel.org
 help / color / mirror / Atom feed
From: Takashi Sakamoto <o-takashi@sakamocchi.jp>
To: tiwai@suse.de
Cc: vinod.koul@intel.com, alsa-devel@alsa-project.org,
	subhransu.s.prusty@intel.com,
	pierre-louis.bossart@linux.intel.com
Subject: [PATCH 2/3] ALSA: pcm: add 'applptr' event of tracepoint
Date: Sun, 11 Jun 2017 15:48:07 +0900	[thread overview]
Message-ID: <20170611064808.30572-3-o-takashi@sakamocchi.jp> (raw)
In-Reply-To: <20170611064808.30572-1-o-takashi@sakamocchi.jp>

In design of ALSA PCM core, both of hardware-side and application-side
position on PCM buffer are maintained as a part of information for
runtime of PCM substream. In a view of ALSA PCM application, these two
positions can be updated by executing ioctl(2) with some commands.

There's an event of tracepoint for hardware-side position; 'hwptr'.
On the other hand, no events for application-side position.

This commit adds a new event for this purpose; 'applptr'. When
the application-side position is changed in kernel space, this event
is probed with useful information for developers.

I note that the event is not probed for all of ALSA PCM applications,
because the application-side position is passively maintained in mmap
programming scenario. In this case, applications should be programmed
with ioctl(2) with SNDRV_PCM_IOCTL_SYNC_PTR to commit the application-side
position to kernel land when it operates any PCM frames. In read/write
programming scenario, this is needless. They're OK just to transfer any
PCM frames by ioctl(2) with SNDRV_PCM_IOCTL_[READ|WRITE][N/I]_FRAMES,
then stuffs in kernel land updates the application-side position and
the event is probed.

My additional note is lock acquisition. The event is probed under acquiring
PCM stream lock. This means that calculation in the event is free from
any hardware events.

Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
---
 sound/core/pcm_lib.c   |  4 ++++
 sound/core/pcm_trace.h | 38 ++++++++++++++++++++++++++++++++++++++
 2 files changed, 42 insertions(+)

diff --git a/sound/core/pcm_lib.c b/sound/core/pcm_lib.c
index d82f1437667f..e73b6e4135f6 100644
--- a/sound/core/pcm_lib.c
+++ b/sound/core/pcm_lib.c
@@ -42,6 +42,7 @@
 #define trace_hwptr(substream, pos, in_interrupt)
 #define trace_xrun(substream)
 #define trace_hw_ptr_error(substream, reason)
+#define trace_applptr(substream, prev, curr)
 #endif
 
 static int fill_silence_frames(struct snd_pcm_substream *substream,
@@ -2119,6 +2120,9 @@ int pcm_lib_apply_appl_ptr(struct snd_pcm_substream *substream,
 			return ret;
 		}
 	}
+
+	trace_applptr(substream, old_appl_ptr, appl_ptr);
+
 	return 0;
 }
 
diff --git a/sound/core/pcm_trace.h b/sound/core/pcm_trace.h
index b63b654da5ff..e672368ab878 100644
--- a/sound/core/pcm_trace.h
+++ b/sound/core/pcm_trace.h
@@ -102,6 +102,44 @@ TRACE_EVENT(hw_ptr_error,
 		  __entry->number, __entry->reason)
 );
 
+TRACE_EVENT(applptr,
+	TP_PROTO(struct snd_pcm_substream *substream, snd_pcm_uframes_t prev, snd_pcm_uframes_t curr),
+	TP_ARGS(substream, prev, curr),
+	TP_STRUCT__entry(
+		__field( unsigned int, card )
+		__field( unsigned int, device )
+		__field( unsigned int, number )
+		__field( unsigned int, stream )
+		__field( snd_pcm_uframes_t, prev )
+		__field( snd_pcm_uframes_t, curr )
+		__field( snd_pcm_uframes_t, avail )
+		__field( snd_pcm_uframes_t, period_size )
+		__field( snd_pcm_uframes_t, buffer_size )
+	),
+	TP_fast_assign(
+		__entry->card = (substream)->pcm->card->number;
+		__entry->device = (substream)->pcm->device;
+		__entry->number = (substream)->number;
+		__entry->stream = (substream)->stream;
+		__entry->prev = (prev);
+		__entry->curr = (curr);
+		__entry->avail = (substream)->stream ? snd_pcm_capture_avail(substream->runtime) : snd_pcm_playback_avail(substream->runtime);
+		__entry->period_size = (substream)->runtime->period_size;
+		__entry->buffer_size = (substream)->runtime->buffer_size;
+	),
+	TP_printk("pcmC%dD%d%s/sub%d: prev=%lu, curr=%lu, avail=%lu, period=%lu, buf=%lu",
+		__entry->card,
+		__entry->device,
+		__entry->stream ? "c" : "p",
+		__entry->number,
+		__entry->prev,
+		__entry->curr,
+		__entry->avail,
+		__entry->period_size,
+		__entry->buffer_size
+	)
+);
+
 #endif /* _PCM_TRACE_H */
 
 /* This part must be outside protection */
-- 
2.11.0

  parent reply	other threads:[~2017-06-11  6:48 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-06-11  6:48 [PATCH 0/3] ALSA: pcm: add 'applptr' event of tracepoint Takashi Sakamoto
2017-06-11  6:48 ` [PATCH 1/3] ALSA: pcm: unify codes to operate application-side position on PCM buffer Takashi Sakamoto
2017-06-11  6:48 ` Takashi Sakamoto [this message]
2017-06-11 16:53   ` [PATCH 2/3] ALSA: pcm: add 'applptr' event of tracepoint Takashi Iwai
2017-06-11 23:55     ` Takashi Sakamoto
2017-06-11  6:48 ` [PATCH 3/3] ALSA: pcm: use %s instead of %c for format of PCM buffer tracepoints Takashi Sakamoto
2017-06-11 17:03 ` [PATCH 0/3] ALSA: pcm: add 'applptr' event of tracepoint Takashi Iwai
2017-06-12  0:08   ` Takashi Sakamoto

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20170611064808.30572-3-o-takashi@sakamocchi.jp \
    --to=o-takashi@sakamocchi.jp \
    --cc=alsa-devel@alsa-project.org \
    --cc=pierre-louis.bossart@linux.intel.com \
    --cc=subhransu.s.prusty@intel.com \
    --cc=tiwai@suse.de \
    --cc=vinod.koul@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.