随笔分类 -  原创

silk mpu
摘要:#include "mpu.h" #include "mbuf.h" #include "media_buffer.h" #include "my_errno.h" #include "mem.h" #include "silk.h" #include "interface/SKP_Silk_SDK_API.h" struct silk_codec { void* obj; S... 阅读全文
posted @ 2016-10-19 00:53 zylthinking 阅读(363) 评论(0) 推荐(0)
mpu
摘要:#include "mpu.h" #include "mem.h" #include "my_errno.h" #include "resampler.h" #include "media_buffer.h" #define same_ptr (void *) (1) static mpu_item* same_link(fourcc** ccptr); extern media_proce... 阅读全文
posted @ 2016-10-19 00:49 zylthinking 阅读(230) 评论(0) 推荐(0)
lock
摘要:#ifndef lock_h #define lock_h #include #include #include "mydef.h" #include "now.h" #define debug_lock 1 typedef struct { intptr_t lck; uintptr_t tid; uintptr_t nr; #if debug_lock ... 阅读全文
posted @ 2016-10-19 00:38 zylthinking 阅读(265) 评论(0) 推荐(0)
myhandle
摘要:#ifndef my_handle_h #define my_handle_h #include #include "mydef.h" #include "mem.h" typedef struct tag_my_handle { int ref; int stack; intptr_t detached; void* ptr; free_t fre... 阅读全文
posted @ 2016-10-19 00:35 zylthinking 阅读(233) 评论(0) 推荐(0)
无锁链表
摘要:#ifndef lkf_h #define lkf_h struct lkf_node { struct lkf_node* next; }; struct lkf_list { struct lkf_node root; struct lkf_node** tail; }; #define LKF_INIT(name) {.root = {NULL}, .tai... 阅读全文
posted @ 2016-10-19 00:30 zylthinking 阅读(1554) 评论(0) 推荐(0)
原子操作与锁
摘要:1. 既然比较两者性能, 必然锁的区域极小, 可以使用原子操作代替2. 若这个极小区域就是操作的全部, 只是频繁被调用, 则看并发的线程数量, 在并发量小时, 线程冲突小, 而一个 yield 可以保证较长时间内其他线程不来打搅, 获得的是一个类似批处理的结果, 性能较原子操作高; 自然, 若仅仅只... 阅读全文
posted @ 2014-05-19 00:42 zylthinking 阅读(4772) 评论(1) 推荐(0)
heap sort
摘要:#include <stdio.h>void heapify(int* intp, unsigned idx, unsigned nr){ unsigned j = idx; while (1) { unsigned i = idx * 2 + 1; if (nr > i && intp[i] > intp[j]) { j = i; } ++i; if (nr > i && intp[i] > intp[j]) { j = i; } ... 阅读全文
posted @ 2013-02-22 15:43 zylthinking 阅读(199) 评论(0) 推荐(0)
逆序对
摘要:算法导论题目: 设 A[0...N] 数组, 若 i < j 且 A[i] > A[j] 则称 (i, j) 为一个逆序对, 给出一个算法, 在最坏 O(nlgn) 的运行时间, 得到任意数组的逆序对个数。#include <stdio.h>#include <stdlib.h>#include <string.h>int merge(int* intp, int a, int b, int c){ int n = c - a; int* p = (int *) malloc(sizeof(int) * n); if (p == NULL) { 阅读全文
posted @ 2013-02-18 16:25 zylthinking 阅读(206) 评论(0) 推荐(0)
用户空间 rcu 的实现
摘要:上一次分析了 classic rcu 在 2.6.28.3 中的实现, 根据它的原理, 在用户空间实现了一份, 性能应该不如内核 rcu, 但整体来讲, 应该比基于锁总线而实现的读写锁要效率高一些。#ifndef rcu_h#define rcu_h#include "list_head.h"struct rcu { int lck; int zombie; struct list_head sync, async, nxtlist, entry; unsigned int nr; int* tlsp; int* intp; int* refp; ... 阅读全文
posted @ 2013-02-06 13:09 zylthinking 阅读(703) 评论(0) 推荐(0)
classic RCU 逻辑分析
摘要:看的是 2.6.18.3 版本的 rcu 代码, 这个版本其实还没有区分什么 tiny rcu, preempt rcu, 这些都出现在以后的版本, 之所以选择这个, 完全是因为刚开始看 rcu 时搜索到的网文引用的代码是这个版本的, 而且也算是早期的实现, 代码比较少, 容易看清脉络。 rcu 的原理大概就相当于一个读写锁, 不同的是实现方式: rcu 要求被读的数据被一个指针指向, 读者先读这个指针, 而后读指针指向的数据; 写者也先读这个指针及其数据, 不同的是它而后分配出一块新内存, 做一次拷贝, 而后修改在这个拷贝上进行, 等修改完毕, 将指针指向这块新内存;而后将旧内存释放掉。.. 阅读全文
posted @ 2013-02-05 17:27 zylthinking 阅读(1006) 评论(0) 推荐(0)
5289A 中断控制器
摘要:本来想翻译一篇国外的文章, 因为不得不说他比我会写多了, 但貌似高质量的文章背后是将一个问题尽量拖长, 像是写小说似的, 很多东西似乎和想要说的无关, 只是为了流畅易懂来的。 全部翻译下来, 太累了, 干脆摘抄部分关键段落, 剩下的自己写。 而且我也有我自己的理解, 英文全文链接在此:http://blog.chinaunix.net/uid-7190305-id-3014030.html。An interrupt source, fed into an 8259A, is known as an IRQ – Interrupt Request. An 8259A has 8IRQ inp.. 阅读全文
posted @ 2013-01-31 11:21 zylthinking 阅读(636) 评论(0) 推荐(0)
伪中断
摘要:1. The interrupt flag (IF) of the 80x86 is reset eitherdirectly (e.g., by a "cli" instruction) or because aninterrupt handler is entered. In the latter case thecorresponding in-service (IS) bit of the 8259A is set(effectively blocking interrupts of lower priority).2. The 8259A receives an 阅读全文
posted @ 2013-01-30 15:23 zylthinking 阅读(906) 评论(0) 推荐(0)
linux page 管理分析(1)
摘要:681/* 682 * Get the lock to a page atomically. 683 */ 684struct page * __find_lock_page (struct address_space *mapping, 685 unsigned long offset, struct page **hash) 686{ 687 struct page *page; 688 689 /* 690 * We scan the hash list read-only. Ad... 阅读全文
posted @ 2013-01-16 16:03 zylthinking 阅读(1934) 评论(0) 推荐(0)
linux do_mmap
摘要:do_mmap 函数自己本身并不真做 mmap, 它基本上只是检查参数, 准备必要的数据结构; 但这也不是没有可说的, 事实上, glibc 函数 mmap 的需要注意的点, 再这个函数里面还真有几个。先看 mmap 原型void* mmap(void* addr, sie_t length, int prot, int flags, int fd, offset_t offset)参数含义可以 man, 不多说, 单看几个prot | flags偏门组合:1. PROT_READ | MAP_SHARED这意思是, 我只读, 但别人的写得给我看到;那么这个和 PROT_READ | MAP_ 阅读全文
posted @ 2013-01-10 13:11 zylthinking 阅读(1503) 评论(0) 推荐(0)
linux mount 过程
摘要:struct inode 里面有 15 个成员最为重要, 分成4类:1. 链表类,i_hash 将 inode 链接入 inode hashtable, 外部可以通过 super_block 指针与 ino 来找到这个 inodei_dentry 为 inode 的 dentry 链表表头, 从而一个 inode 可以在文件树中有多个硬链接i_list 将 inode 链接入 inode_used 链表2. 属性类i_ino, inode numberi_mode, 文件 RWX 属性及文件类型, 比如是否是文件夹, 普通文件, 或者设备文件等i_dev, inode 所在设备的设备号, 从 阅读全文
posted @ 2013-01-07 00:08 zylthinking 阅读(1436) 评论(1) 推荐(1)
gfp_xxx 的理解
摘要:gfp_mask参数可以设置很多值,一下是各个取值的用处(直接引用至LKD):#define GFP_ATOMIC (__GFP_HIGH)GFP_ATOMICThe allocation is high priority and must not sleep. This is the flagto use in interrupt handlers, in bottom halves, while holding a spinlock, and in other situations where you cannot sleep.#define GFP_NOWAIT (GFP_A... 阅读全文
posted @ 2012-08-07 01:42 zylthinking 阅读(2610) 评论(0) 推荐(0)