Commit d26ab5a3 authored by Xabier Marquiegui's avatar Xabier Marquiegui Committed by David S. Miller

ptp: Replace timestamp event queue with linked list

Introduce linked lists to access the timestamp event queue.
Signed-off-by: default avatarXabier Marquiegui <reibax@gmail.com>
Suggested-by: default avatarRichard Cochran <richardcochran@gmail.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 60c69466
...@@ -439,10 +439,14 @@ __poll_t ptp_poll(struct posix_clock_context *pccontext, struct file *fp, ...@@ -439,10 +439,14 @@ __poll_t ptp_poll(struct posix_clock_context *pccontext, struct file *fp,
{ {
struct ptp_clock *ptp = struct ptp_clock *ptp =
container_of(pccontext->clk, struct ptp_clock, clock); container_of(pccontext->clk, struct ptp_clock, clock);
struct timestamp_event_queue *queue;
poll_wait(fp, &ptp->tsev_wq, wait); poll_wait(fp, &ptp->tsev_wq, wait);
return queue_cnt(&ptp->tsevq) ? EPOLLIN : 0; /* Extract only the first element in the queue list */
queue = list_first_entry(&ptp->tsevqs, struct timestamp_event_queue, qlist);
return queue_cnt(queue) ? EPOLLIN : 0;
} }
#define EXTTS_BUFSIZE (PTP_BUF_TIMESTAMPS * sizeof(struct ptp_extts_event)) #define EXTTS_BUFSIZE (PTP_BUF_TIMESTAMPS * sizeof(struct ptp_extts_event))
...@@ -452,12 +456,16 @@ ssize_t ptp_read(struct posix_clock_context *pccontext, uint rdflags, ...@@ -452,12 +456,16 @@ ssize_t ptp_read(struct posix_clock_context *pccontext, uint rdflags,
{ {
struct ptp_clock *ptp = struct ptp_clock *ptp =
container_of(pccontext->clk, struct ptp_clock, clock); container_of(pccontext->clk, struct ptp_clock, clock);
struct timestamp_event_queue *queue = &ptp->tsevq; struct timestamp_event_queue *queue;
struct ptp_extts_event *event; struct ptp_extts_event *event;
unsigned long flags; unsigned long flags;
size_t qcnt, i; size_t qcnt, i;
int result; int result;
/* Extract only the first element in the queue list */
queue = list_first_entry(&ptp->tsevqs, struct timestamp_event_queue,
qlist);
if (cnt % sizeof(struct ptp_extts_event) != 0) if (cnt % sizeof(struct ptp_extts_event) != 0)
return -EINVAL; return -EINVAL;
......
...@@ -169,12 +169,21 @@ static struct posix_clock_operations ptp_clock_ops = { ...@@ -169,12 +169,21 @@ static struct posix_clock_operations ptp_clock_ops = {
static void ptp_clock_release(struct device *dev) static void ptp_clock_release(struct device *dev)
{ {
struct ptp_clock *ptp = container_of(dev, struct ptp_clock, dev); struct ptp_clock *ptp = container_of(dev, struct ptp_clock, dev);
struct timestamp_event_queue *tsevq;
unsigned long flags;
ptp_cleanup_pin_groups(ptp); ptp_cleanup_pin_groups(ptp);
kfree(ptp->vclock_index); kfree(ptp->vclock_index);
mutex_destroy(&ptp->tsevq_mux); mutex_destroy(&ptp->tsevq_mux);
mutex_destroy(&ptp->pincfg_mux); mutex_destroy(&ptp->pincfg_mux);
mutex_destroy(&ptp->n_vclocks_mux); mutex_destroy(&ptp->n_vclocks_mux);
/* Delete first entry */
tsevq = list_first_entry(&ptp->tsevqs, struct timestamp_event_queue,
qlist);
spin_lock_irqsave(&tsevq->lock, flags);
list_del(&tsevq->qlist);
spin_unlock_irqrestore(&tsevq->lock, flags);
kfree(tsevq);
ida_free(&ptp_clocks_map, ptp->index); ida_free(&ptp_clocks_map, ptp->index);
kfree(ptp); kfree(ptp);
} }
...@@ -206,6 +215,7 @@ struct ptp_clock *ptp_clock_register(struct ptp_clock_info *info, ...@@ -206,6 +215,7 @@ struct ptp_clock *ptp_clock_register(struct ptp_clock_info *info,
struct device *parent) struct device *parent)
{ {
struct ptp_clock *ptp; struct ptp_clock *ptp;
struct timestamp_event_queue *queue = NULL;
int err = 0, index, major = MAJOR(ptp_devt); int err = 0, index, major = MAJOR(ptp_devt);
size_t size; size_t size;
...@@ -228,7 +238,12 @@ struct ptp_clock *ptp_clock_register(struct ptp_clock_info *info, ...@@ -228,7 +238,12 @@ struct ptp_clock *ptp_clock_register(struct ptp_clock_info *info,
ptp->info = info; ptp->info = info;
ptp->devid = MKDEV(major, index); ptp->devid = MKDEV(major, index);
ptp->index = index; ptp->index = index;
spin_lock_init(&ptp->tsevq.lock); INIT_LIST_HEAD(&ptp->tsevqs);
queue = kzalloc(sizeof(*queue), GFP_KERNEL);
if (!queue)
goto no_memory_queue;
spin_lock_init(&queue->lock);
list_add_tail(&queue->qlist, &ptp->tsevqs);
mutex_init(&ptp->tsevq_mux); mutex_init(&ptp->tsevq_mux);
mutex_init(&ptp->pincfg_mux); mutex_init(&ptp->pincfg_mux);
mutex_init(&ptp->n_vclocks_mux); mutex_init(&ptp->n_vclocks_mux);
...@@ -333,6 +348,9 @@ struct ptp_clock *ptp_clock_register(struct ptp_clock_info *info, ...@@ -333,6 +348,9 @@ struct ptp_clock *ptp_clock_register(struct ptp_clock_info *info,
mutex_destroy(&ptp->tsevq_mux); mutex_destroy(&ptp->tsevq_mux);
mutex_destroy(&ptp->pincfg_mux); mutex_destroy(&ptp->pincfg_mux);
mutex_destroy(&ptp->n_vclocks_mux); mutex_destroy(&ptp->n_vclocks_mux);
list_del(&queue->qlist);
kfree(queue);
no_memory_queue:
ida_free(&ptp_clocks_map, index); ida_free(&ptp_clocks_map, index);
no_slot: no_slot:
kfree(ptp); kfree(ptp);
...@@ -375,6 +393,7 @@ EXPORT_SYMBOL(ptp_clock_unregister); ...@@ -375,6 +393,7 @@ EXPORT_SYMBOL(ptp_clock_unregister);
void ptp_clock_event(struct ptp_clock *ptp, struct ptp_clock_event *event) void ptp_clock_event(struct ptp_clock *ptp, struct ptp_clock_event *event)
{ {
struct timestamp_event_queue *tsevq;
struct pps_event_time evt; struct pps_event_time evt;
switch (event->type) { switch (event->type) {
...@@ -383,7 +402,10 @@ void ptp_clock_event(struct ptp_clock *ptp, struct ptp_clock_event *event) ...@@ -383,7 +402,10 @@ void ptp_clock_event(struct ptp_clock *ptp, struct ptp_clock_event *event)
break; break;
case PTP_CLOCK_EXTTS: case PTP_CLOCK_EXTTS:
enqueue_external_timestamp(&ptp->tsevq, event); /* Enqueue timestamp on all queues */
list_for_each_entry(tsevq, &ptp->tsevqs, qlist) {
enqueue_external_timestamp(tsevq, event);
}
wake_up_interruptible(&ptp->tsev_wq); wake_up_interruptible(&ptp->tsev_wq);
break; break;
......
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
#include <linux/ptp_clock.h> #include <linux/ptp_clock.h>
#include <linux/ptp_clock_kernel.h> #include <linux/ptp_clock_kernel.h>
#include <linux/time.h> #include <linux/time.h>
#include <linux/list.h>
#define PTP_MAX_TIMESTAMPS 128 #define PTP_MAX_TIMESTAMPS 128
#define PTP_BUF_TIMESTAMPS 30 #define PTP_BUF_TIMESTAMPS 30
...@@ -25,6 +26,7 @@ struct timestamp_event_queue { ...@@ -25,6 +26,7 @@ struct timestamp_event_queue {
int head; int head;
int tail; int tail;
spinlock_t lock; spinlock_t lock;
struct list_head qlist;
}; };
struct ptp_clock { struct ptp_clock {
...@@ -35,7 +37,7 @@ struct ptp_clock { ...@@ -35,7 +37,7 @@ struct ptp_clock {
int index; /* index into clocks.map */ int index; /* index into clocks.map */
struct pps_device *pps_source; struct pps_device *pps_source;
long dialed_frequency; /* remembers the frequency adjustment */ long dialed_frequency; /* remembers the frequency adjustment */
struct timestamp_event_queue tsevq; /* simple fifo for time stamps */ struct list_head tsevqs; /* timestamp fifo list */
struct mutex tsevq_mux; /* one process at a time reading the fifo */ struct mutex tsevq_mux; /* one process at a time reading the fifo */
struct mutex pincfg_mux; /* protect concurrent info->pin_config access */ struct mutex pincfg_mux; /* protect concurrent info->pin_config access */
wait_queue_head_t tsev_wq; wait_queue_head_t tsev_wq;
......
...@@ -75,12 +75,16 @@ static ssize_t extts_fifo_show(struct device *dev, ...@@ -75,12 +75,16 @@ static ssize_t extts_fifo_show(struct device *dev,
struct device_attribute *attr, char *page) struct device_attribute *attr, char *page)
{ {
struct ptp_clock *ptp = dev_get_drvdata(dev); struct ptp_clock *ptp = dev_get_drvdata(dev);
struct timestamp_event_queue *queue = &ptp->tsevq; struct timestamp_event_queue *queue;
struct ptp_extts_event event; struct ptp_extts_event event;
unsigned long flags; unsigned long flags;
size_t qcnt; size_t qcnt;
int cnt = 0; int cnt = 0;
/* The sysfs fifo will always draw from the fist queue */
queue = list_first_entry(&ptp->tsevqs, struct timestamp_event_queue,
qlist);
memset(&event, 0, sizeof(event)); memset(&event, 0, sizeof(event));
if (mutex_lock_interruptible(&ptp->tsevq_mux)) if (mutex_lock_interruptible(&ptp->tsevq_mux))
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment