/* * Update the current task's runtime statistics. Skip current tasks that * are not in our scheduling class. */ static inline void update_curr_rt(struct rq *rq) { struct task_struct *curr = rq->curr; u64 delta_exec; if (!task_has_rt_policy(curr)) return; delta_exec = rq->clock - curr->se.exec_start; if (unlikely((s64)delta_exec < 0)) delta_exec = 0; schedstat_set(curr->se.exec_max, max(curr->se.exec_max, delta_exec)); curr->se.sum_exec_runtime += delta_exec; curr->se.exec_start = rq->clock; }
static ssize_t lpa_if_write(struct file *file, const char __user *buf, size_t count, loff_t *pos) { struct lpa_if *lpa_if = file->private_data; struct audio_buffer *ab; const char __user *start = buf; int xfer, rc; struct sched_param s = { .sched_priority = 1 }; int old_prio = current->rt_priority; int old_policy = current->policy; int cap_nice = cap_raised(current_cap(), CAP_SYS_NICE); /* just for this write, set us real-time */ if (!task_has_rt_policy(current)) { struct cred *new = prepare_creds(); cap_raise(new->cap_effective, CAP_SYS_NICE); commit_creds(new); if ((sched_setscheduler(current, SCHED_RR, &s)) < 0) pr_err("sched_setscheduler failed\n"); } mutex_lock(&lpa_if->lock); if (dma_buf_index < 2) { ab = lpa_if->audio_buf + dma_buf_index; if (copy_from_user(ab->data, buf, count)) { pr_err("copy from user failed\n"); rc = 0; goto end; } mb(); pr_debug("prefill: count %u audio_buf[%u].size %u\n", count, dma_buf_index, ab->size); ab->used = 1; dma_buf_index++; rc = count; goto end; } if (lpa_if->config != 1) { pr_err("AUDIO_START did not happen\n"); rc = 0; goto end; } while (count > 0) { ab = lpa_if->audio_buf + lpa_if->cpu_buf; rc = wait_event_timeout(lpa_if->wait, (ab->used == 0), 10 * HZ); if (!rc) { pr_err("wait_event_timeout failed\n"); rc = buf - start; goto end; } xfer = count; if (xfer > lpa_if->dma_period_sz) xfer = lpa_if->dma_period_sz; if (copy_from_user(ab->data, buf, xfer)) { pr_err("copy from user failed\n"); rc = buf - start; goto end; } mb(); buf += xfer; count -= xfer; ab->used = 1; pr_debug("xfer %d, size %d, used %d cpu_buf %d\n", xfer, ab->size, ab->used, lpa_if->cpu_buf); lpa_if->cpu_buf++; lpa_if->cpu_buf = lpa_if->cpu_buf % lpa_if->cfg.buffer_count; } rc = buf - start; end: mutex_unlock(&lpa_if->lock); /* restore old scheduling policy */ if (!rt_policy(old_policy)) { struct sched_param v = { .sched_priority = old_prio }; if ((sched_setscheduler(current, old_policy, &v)) < 0) pr_err("sched_setscheduler failed\n"); if (likely(!cap_nice)) { struct cred *new = prepare_creds(); cap_lower(new->cap_effective, CAP_SYS_NICE); commit_creds(new); } } return rc; } static int lpa_if_release(struct inode *inode, struct file *file) { struct lpa_if *lpa_if = file->private_data; hdmi_audio_packet_enable(0); wait_for_dma_cnt_stop(lpa_if->dma_ch); hdmi_audio_enable(0, HDMI_AUDIO_FIFO_WATER_MARK); if (lpa_if->config) { unregister_dma_irq_handler(lpa_if->dma_ch); dai_stop_hdmi(lpa_if->dma_ch); lpa_if->config = 0; } core_req_bus_bandwith(AUDIO_IF_BUS_ID, 0, 0); if (hdmi_msm_audio_get_sample_rate() != HDMI_SAMPLE_RATE_48KHZ) hdmi_msm_audio_sample_rate_reset(HDMI_SAMPLE_RATE_48KHZ); return 0; } static const struct file_operations lpa_if_fops = { .owner = THIS_MODULE, .open = lpa_if_open, .write = lpa_if_write, .release = lpa_if_release, .unlocked_ioctl = lpa_if_ioctl, }; struct miscdevice lpa_if_misc = { .minor = MISC_DYNAMIC_MINOR, .name = "msm_lpa_if_out", .fops = &lpa_if_fops, }; static int __init lpa_if_init(void) { int rc; lpa_if_ptr = kzalloc(sizeof(struct lpa_if), GFP_KERNEL); if (!lpa_if_ptr) { pr_info("No mem for lpa-if\n"); return -ENOMEM; } mutex_init(&lpa_if_ptr->lock); init_waitqueue_head(&lpa_if_ptr->wait); lpa_if_ptr->buffer = dma_alloc_coherent(NULL, DMA_ALLOC_BUF_SZ, &(lpa_if_ptr->buffer_phys), GFP_KERNEL); if (!lpa_if_ptr->buffer) { pr_err("dma_alloc_coherent failed\n"); kfree(lpa_if_ptr); return -ENOMEM; } pr_info("lpa_if_ptr 0x%08x buf_vir 0x%08x buf_phy 0x%08x " " buf_zise %u\n", (u32)lpa_if_ptr, (u32)(lpa_if_ptr->buffer), lpa_if_ptr->buffer_phys, DMA_ALLOC_BUF_SZ); rc = misc_register(&lpa_if_misc); if (rc < 0) { pr_err("misc_register failed\n"); dma_free_coherent(NULL, DMA_ALLOC_BUF_SZ, lpa_if_ptr->buffer, lpa_if_ptr->buffer_phys); kfree(lpa_if_ptr); } return rc; } device_initcall(lpa_if_init);
// Jagan- static ssize_t pcm_write(struct file *file, const char __user *buf, size_t count, loff_t *pos) { struct pcm *pcm = file->private_data; struct audio_client *ac; struct audio_buffer *ab; const char __user *start = buf; int xfer; #if 0 // Jagan+ if(!task_has_rt_policy(current)) { struct sched_param param = { .sched_priority = 99 }; printk(KERN_INFO "pcm_write to change to RT tid = %d\n", current->pid); if(sched_setscheduler_nocheck(current, SCHED_FIFO, ¶m )!=0) { printk(KERN_ERR "pcm_write fail to change to RT\n"); } } // Jagan- #endif if (!pcm->ac) pcm_ioctl(file, AUDIO_START, 0); ac = pcm->ac; if (!ac) return -ENODEV; while (count > 0) { ab = ac->buf + ac->cpu_buf; if (ab->used) if (!wait_event_timeout(ac->wait, (ab->used == 0), 5*HZ)) { audio_client_dump(ac); pr_err("[%s:%s] timeout. dsp dead?\n", __MM_FILE__, __func__); q6audio_dsp_not_responding(); } xfer = count; if (xfer > ab->size) xfer = ab->size; if (copy_from_user(ab->data, buf, xfer)) return -EFAULT; buf += xfer; count -= xfer; ab->used = 1; ab->actual_size = xfer; q6audio_write(ac, ab); ac->cpu_buf ^= 1; } return buf - start; } static int pcm_release(struct inode *inode, struct file *file) { struct pcm *pcm = file->private_data; if (pcm->ac) q6audio_close(pcm->ac); kfree(pcm); pr_info("[%s:%s] release\n", __MM_FILE__, __func__); // Jagan+ if (unlikely(1 == Is_first_boot_flag)) Is_first_boot_flag = 0; // Jagan- return 0; } static struct file_operations pcm_fops = { .owner = THIS_MODULE, .open = pcm_open, .write = pcm_write, .release = pcm_release, .unlocked_ioctl = pcm_ioctl, }; struct miscdevice pcm_misc = { .minor = MISC_DYNAMIC_MINOR, .name = "msm_pcm_out", .fops = &pcm_fops, }; static int __init pcm_init(void) { return misc_register(&pcm_misc); } device_initcall(pcm_init);