内核数据结构-----队列kfifo.h (4.0.8)较新的内核版本

linux内核之无锁缓冲队列kfifo原理(结合项目实践) Linux kernel里面从来就不缺少简洁,优雅和高效的代码,只是我们缺少发现和品味的眼光。在Linux kernel里面,简洁并不表示代码使用神出鬼没的超然技巧,相反,它使用的不过是大家非常熟悉的基础数据结构,但是kernel开发者能从基础的数据结构中,提炼出优美的特性。 kfifo就是这样的一类优美代码,它十分简洁,绝无多余的一行代码,却非常高效。 关于kfifo信息如下: 本文分析的源代码版本: 2.6.24.4 kfifo的定义文件: kernel/kfifo.c kfifo的头文件: incl 阅读详情

   现在市面上能买到的书大多都是2.6.X内核的,可是现在内核都出到4.2了其中也是发生了翻天覆地的变化,我学习开始内核就想从内核数据结构看起,看以前旧代码真心没什么意思,不如开拓下荒地。

队列这个东西其实以前也接触过,也写过一版通用的代码,其实一般的代码都是OK 的,但是最近开始我的内核之旅了,我还是想看看内核是如何实现队列的,从上次分析list.h 看来,内核的数据结构还是非常复杂的,复杂的看不懂,看懂了不会用,。。。。

            任何操作系统都是离不开编程模型的,其中,生产者与消费者模型是很常见的,也和我们今天分析的队列结构很有关系。其实使用队列来实现这个编程模型时最简单的一种实现方式了,所以我们就来分析分析它。

为了提高英语水平以及为后续参加开源活动我都会翻译源码注释

我用的是4.0.8 的内核,它与之前2.6.* 版本的内核已经有了很大的区别。

/*
 * How to porting drivers to the new generic FIFO API:
 *
 * - Modify the declaration of the "struct kfifo *" object into a
 *   in-place "struct kfifo" object
 * - Init the in-place object with kfifo_alloc() or kfifo_init()
 *   Note: The address of the in-place "struct kfifo" object must be
 *   passed as the first argument to this functions
 * - Replace the use of __kfifo_put into kfifo_in and __kfifo_get
 *   into kfifo_out
 * - Replace the use of kfifo_put into kfifo_in_spinlocked and kfifo_get
 *   into kfifo_out_spinlocked
 *   Note: the spinlock pointer formerly passed to kfifo_init/kfifo_alloc
 *   must be passed now to the kfifo_in_spinlocked and kfifo_out_spinlocked
 *   as the last parameter
 * - The formerly __kfifo_* functions are renamed into kfifo_*
 */
        如何将队列移植到一个新的驱动中:

修改结构体的定义,改成需要的结构体。

使用kfifo_alloc( ) 或者 kfifo_init( ) 函数初始化已经定义的对象,注意:结构体的私之必须经过函数的确定.

        修改kfifo_put 为kfifo_in_spinlocked    kfifo_get为 kfifo_out_spinlocked    (spinlocked : 自旋锁)

       __kfifo_ * 被修改为  kfifo_ *

 

/*
 * Note about locking : There is no locking required until only * one reader
 * and one writer is using the fifo and no kfifo_reset() will be * called
 *  kfifo_reset_out() can be safely used, until it will be only called
 * in the reader thread.
 *  For multiple writer and one reader there is only a need to lock the writer.
 * And vice versa for only one writer and multiple reader there is only a need
 * to lock the reader.
 */

       关于锁的注意:这里没有锁的要求,除非有一个读取的动作的同时还有一个写的动作在使用队列,并且没有调用kfifo_reset( ) 函数,这时候使用kfifo_reset_out ( )函数就是安全的,这个函数一般在读动作的线程中调用。

      对于多个写动作和一个读动作,只需要锁住写动作,反过来,只有一个写动作且有多个读动作,只需要锁住读动作。(真体现了内核数据结构链表的设计精巧)

      内核的队列结构和我们平时用的队列不是很相同,首先看下结构体:

struct __kfifo {
	unsigned int	in;
	unsigned int	out;
	unsigned int	mask;
	unsigned int	esize;
	void		*data;
};

这就是队列的部分结构体,它的入队出队是根据偏移量来决定的。

@in:入队偏移量

@out :出队偏移量

@mask: 表示队列的总大小(静态分配时,队列的固定总长度)

@eszie: 数据域大小

@data:数据域指针

   下面的是以前的结构体不得不说内核的改变还是很大的

struct kfifo {
	unsigned char *buffer;	/* the buffer holding the data */
	unsigned int size;	/* the size of the allocated buffer */
	unsigned int in;	/* data is added at offset (in % size) */
	unsigned int out;	/* data is extracted from off. (out % size) */
	spinlock_t *lock;	/* protects concurrent modifications */
};


真是区别很大。


上边基本上是关于新旧内核的区别,现在开始正式分析代码:

首先看kfifo 结构体。

这里有两个结构体声明,一个是动态分配结构体,一个是静态分配结构体。但是这两个结构体的定义都是用宏实现的也算是殊途同归吧。

先看动态的:

/*
 * define compatibility "struct kfifo" for dynamic allocated fifos
 */
struct kfifo __STRUCT_KFIFO_PTR(unsigned char, 0, void);
这是动态分配结构体

#define __STRUCT_KFIFO_PTR(type, recsize, ptrtype) \
{ \
	__STRUCT_KFIFO_COMMON(type, recsize, ptrtype); \
	type		buf[0]; \
}
@type : 元素类型;

@recsize: 队列长度

@ptrtype: 结构体指针类型

@buf[0] 中存储的就是一个队列的元素

下面分析其中的宏

#define __STRUCT_KFIFO_COMMON(datatype, recsize, ptrtype) \
	union { \
		struct __kfifo	kfifo; \
		datatype	*type; \
		const datatype	*const_type; \
		char		(*rectype)[recsize]; \
		ptrtype		*ptr; \
		ptrtype const	*ptr_const; \
	}

这是一个联合结构体

@datatype  :数据元素类型

@recsize:  队列长度

@ptrtypr :  指针类型

这个联合结构体包含了这个队列元素的一切信息,它的类型,偏移量,指针类型等信息;


现在在来看看静态分配的队列:

/**
 * DECLARE_KFIFO - macro to declare a fifo object
 * @fifo: name of the declared fifo
 * @type: type of the fifo elements
 * @size: the number of elements in the fifo, this must be a power of 2
 */
#define DECLARE_KFIFO(fifo, type, size)	STRUCT_KFIFO(type, size) fifo

静态分配也是有宏来实现的。

@fifo : 声明队列的对象;

@type:队列元素类型;

@size:队列的元素个数,其中个数必须是2的幂;

/**
 * DECLARE_KFIFO_PTR - macro to declare a fifo pointer object
 * @fifo: name of the declared fifo
 * @type: type of the fifo elements
 */
#define DECLARE_KFIFO_PTR(fifo, type)	STRUCT_KFIFO_PTR(type) fifo
同上,也是静态的但是只是定义一个指针。


#define STRUCT_KFIFO(type, size) \
	struct __STRUCT_KFIFO(type, size, 0, type)
#define __STRUCT_KFIFO(type, size, recsize, ptrtype) \
{ \
	__STRUCT_KFIFO_COMMON(type, recsize, ptrtype); \
	type		buf[((size < 2) || (size & (size - 1))) ? -1 : size]; \
}
与是调用两个宏,同时定义了buf 队列的空间。并且调用了__STRUCT_KFIFO_COMMON(type, recsize, ptrtype); 初始化了详细的队列信息;

下面来看看初始化:

首先看一下初始化的函数,这是一个宏定义函数:

/**
 * INIT_KFIFO - Initialize a fifo declared by DECLARE_KFIFO
 * @fifo: name of the declared fifo datatype
 */
#define INIT_KFIFO(fifo) \
(void)({ \
	typeof(&(fifo)) __tmp = &(fifo); \
	struct __kfifo *__kfifo = &__tmp->kfifo; \
	__kfifo->in = 0; \
	__kfifo->out = 0; \
	__kfifo->mask = __is_kfifo_ptr(__tmp) ? 0 : ARRAY_SIZE(__tmp->buf) - 1;\
	__kfifo->esize = sizeof(*__tmp->buf); \
	__kfifo->data = __is_kfifo_ptr(__tmp) ?  NULL : __tmp->buf; \
})
这个宏将队列的信息初始化,这个初始化是针对静态定义的队列使用的;

/**
 * DEFINE_KFIFO - macro to define and initialize a fifo
 * @fifo: name of the declared fifo datatype
 * @type: type of the fifo elements
 * @size: the number of elements in the fifo, this must be a power of 2
 *
 * Note: the macro can be used for global and local fifo data type variables.
 */
#define DEFINE_KFIFO(fifo, type, size) \
	DECLARE_KFIFO(fifo, type, size) = \
	(typeof(fifo)) { \
		{ \
			{ \
			.in	= 0, \
			.out	= 0, \
			.mask	= __is_kfifo_ptr(&(fifo)) ? \
				  0 : \
				  ARRAY_SIZE((fifo).buf) - 1, \
			.esize	= sizeof(*(fifo).buf), \
			.data	= __is_kfifo_ptr(&(fifo)) ? \
				NULL : \
				(fifo).buf, \
			} \
		} \
	}
这个定义是比较通用的一种定义和初始化方式。参数:

@fifo:已经定义的队列结构名称;

@type:元素类型名称;

@size:队列中元素个数,必须是2 的幂;

Note:这个宏可以适用与全局的以及本地的队列数据类型;

/**
 * kfifo_initialized - Check if the fifo is initialized
 * @fifo: address of the fifo to check
 *
 * Return %true if fifo is initialized, otherwise %false.
 * Assumes the fifo was 0 before.
 */
#define kfifo_initialized(fifo) ((fifo)->kfifo.mask)
检查队列是否被初始化过,假设0是未被初始化;


/**
 * kfifo_esize - returns the size of the element managed by the fifo
 * @fifo: address of the fifo to be used
 */
#define kfifo_esize(fifo)	((fifo)->kfifo.esize)

返回队列可以管理的队列的长度;

/**
 * kfifo_recsize - returns the size of the record length field
 * @fifo: address of the fifo to be used
 */
#define kfifo_recsize(fifo)	(sizeof(*(fifo)->rectype))

返回记录长度字段大小;

/*
 * helper macro to distinguish between real in place fifo where the fifo
 * array is a part of the structure and the fifo type where the array is
 * outside of the fifo structure.
 */
#define	__is_kfifo_ptr(fifo)	(sizeof(*fifo) == sizeof(struct __kfifo))

这个宏用来确定_kfifo 是这个结构体的一部分并且确定传进来的类型是外部的宿主类型。


/**
 * kfifo_size - returns the size of the fifo in elements
 * @fifo: address of the fifo to be used
 */
#define kfifo_size(fifo)	((fifo)->kfifo.mask + 1)

返回队列中可以存放元素的长度;

/**
 * kfifo_reset - removes the entire fifo content
 * @fifo: address of the fifo to be used
 *
 * Note: usage of kfifo_reset() is dangerous. It should be only called when the
 * fifo is exclusived locked or when it is secured that no other thread is
 * accessing the fifo.
 */
#define kfifo_reset(fifo) \
(void)({ \
	typeof((fifo) + 1) __tmp = (fifo); \
	__tmp->kfifo.in = __tmp->kfifo.out = 0; \
})

/**
 * kfifo_reset_out - skip fifo content
 * @fifo: address of the fifo to be used
 *
 * Note: The usage of kfifo_reset_out() is safe until it will be only called
 * from the reader thread and there is only one concurrent reader. Otherwise
 * it is dangerous and must be handled in the same way as kfifo_reset().
 */
#define kfifo_reset_out(fifo)	\
(void)({ \
	typeof((fifo) + 1) __tmp = (fifo); \
	__tmp->kfifo.out = __tmp->kfifo.in; \
})

/**
 * kfifo_len - returns the number of used elements in the fifo
 * @fifo: address of the fifo to be used
 */
#define kfifo_len(fifo) \
({ \
	typeof((fifo) + 1) __tmpl = (fifo); \
	__tmpl->kfifo.in - __tmpl->kfifo.out; \
})
返回队列中已经存在的(已经在队列中的元素)个数;


/**
 * kfifo_is_empty - returns true if the fifo is empty
 * @fifo: address of the fifo to be used
 */
#define	kfifo_is_empty(fifo) \
({ \
	typeof((fifo) + 1) __tmpq = (fifo); \
	__tmpq->kfifo.in == __tmpq->kfifo.out; \
})

/**

队列是否为空;

/**
 * kfifo_is_full - returns true if the fifo is full
 * @fifo: address of the fifo to be used
 */
#define	kfifo_is_full(fifo) \
({ \
	typeof((fifo) + 1) __tmpq = (fifo); \
	kfifo_len(__tmpq) > __tmpq->kfifo.mask; \
})

队列是否已经满了;


/**
 * kfifo_avail - returns the number of unused elements in the fifo
 * @fifo: address of the fifo to be used
 */
#define	kfifo_avail(fifo) \
__kfifo_uint_must_check_helper( \
({ \
	typeof((fifo) + 1) __tmpq = (fifo); \
	const size_t __recsize = sizeof(*__tmpq->rectype); \
	unsigned int __avail = kfifo_size(__tmpq) - kfifo_len(__tmpq); \
	(__recsize) ? ((__avail <= __recsize) ? 0 : \
	__kfifo_max_r(__avail - __recsize, __recsize)) : \
	__avail; \
}) \
)

返回队列中没有被使用的元素个数。


/**
 * kfifo_alloc - dynamically allocates a new fifo buffer
 * @fifo: pointer to the fifo
 * @size: the number of elements in the fifo, this must be a power of 2
 * @gfp_mask: get_free_pages mask, passed to kmalloc()
 *
 * This macro dynamically allocates a new fifo buffer.
 *
 * The numer of elements will be rounded-up to a power of 2.
 * The fifo will be release with kfifo_free().
 * Return 0 if no error, otherwise an error code.
 */
#define kfifo_alloc(fifo, size, gfp_mask) \
__kfifo_int_must_check_helper( \
({ \
	typeof((fifo) + 1) __tmp = (fifo); \
	struct __kfifo *__kfifo = &__tmp->kfifo; \
	__is_kfifo_ptr(__tmp) ? \
	__kfifo_alloc(__kfifo, size, sizeof(*__tmp->type), gfp_mask) : \
	-EINVAL; \
}) \
)
队列动态分配一片新的空间,旧的空间会被释放。

@fifo:指向队列的指针

@size:队列中元素的个数

@标记,使用系统调用动态分配空间;

/**
 * kfifo_free - frees the fifo
 * @fifo: the fifo to be freed
 */
#define kfifo_free(fifo) \
({ \
	typeof((fifo) + 1) __tmp = (fifo); \
	struct __kfifo *__kfifo = &__tmp->kfifo; \
	if (__is_kfifo_ptr(__tmp)) \
		__kfifo_free(__kfifo); \
})
释放这个队列;

/**
 * kfifo_init - initialize a fifo using a preallocated buffer
 * @fifo: the fifo to assign the buffer
 * @buffer: the preallocated buffer to be used
 * @size: the size of the internal buffer, this have to be a power of 2
 *
 * This macro initialize a fifo using a preallocated buffer.
 *
 * The numer of elements will be rounded-up to a power of 2.
 * Return 0 if no error, otherwise an error code.
 */
#define kfifo_init(fifo, buffer, size) \
({ \
	typeof((fifo) + 1) __tmp = (fifo); \
	struct __kfifo *__kfifo = &__tmp->kfifo; \
	__is_kfifo_ptr(__tmp) ? \
	__kfifo_init(__kfifo, buffer, size, sizeof(*__tmp->type)) : \
	-EINVAL; \
})
初始化一个队列,使用预先分配的一片空间;


/**
 * kfifo_put - put data into the fifo
 * @fifo: address of the fifo to be used
 * @val: the data to be added
 *
 * This macro copies the given value into the fifo.
 * It returns 0 if the fifo was full. Otherwise it returns the number
 * processed elements.
 *
 * Note that with only one concurrent reader and one concurrent
 * writer, you don't need extra locking to use these macro.
 */
#define	kfifo_put(fifo, val) \
({ \
	typeof((fifo) + 1) __tmp = (fifo); \
	typeof(*__tmp->const_type) __val = (val); \
	unsigned int __ret; \
	size_t __recsize = sizeof(*__tmp->rectype); \
	struct __kfifo *__kfifo = &__tmp->kfifo; \
	if (__recsize) \
		__ret = __kfifo_in_r(__kfifo, &__val, sizeof(__val), \
			__recsize); \
	else { \
		__ret = !kfifo_is_full(__tmp); \
		if (__ret) { \
			(__is_kfifo_ptr(__tmp) ? \
			((typeof(__tmp->type))__kfifo->data) : \
			(__tmp->buf) \
			)[__kfifo->in & __tmp->kfifo.mask] = \     此处的这个与操作可以确定入队的位置。
				(typeof(*__tmp->type))__val; \
			smp_wmb(); \
			__kfifo->in++; \
		} \
	} \
	__ret; \
})
将一个数据入队列;

@fifo:将要被使用的队列的地址

@val:需要被加入的数据

这个宏将这个数据的一份拷贝加入队列,如果返回0,那么这个队列已经满了,否则它返回处理的元素所在位置;

注意:如果只有一个并行的读者(进程)和一个并行的(写者)进程,你不需要确定这个队列已经被锁,直接可以使用。

这一有一个smp_wmb ( ) 者是CPU的写内存屏障。这里写应当,必须是一个原子操作;


/**
 * kfifo_get - get data from the fifo
 * @fifo: address of the fifo to be used
 * @val: address where to store the data
 *
 * This macro reads the data from the fifo.
 * It returns 0 if the fifo was empty. Otherwise it returns the number
 * processed elements.
 *
 * Note that with only one concurrent reader and one concurrent
 * writer, you don't need extra locking to use these macro.
 */
#define	kfifo_get(fifo, val) \
__kfifo_uint_must_check_helper( \
({ \
	typeof((fifo) + 1) __tmp = (fifo); \
	typeof(__tmp->ptr) __val = (val); \
	unsigned int __ret; \
	const size_t __recsize = sizeof(*__tmp->rectype); \
	struct __kfifo *__kfifo = &__tmp->kfifo; \
	if (__recsize) \
		__ret = __kfifo_out_r(__kfifo, __val, sizeof(*__val), \
			__recsize); \
	else { \
		__ret = !kfifo_is_empty(__tmp); \
		if (__ret) { \
			*(typeof(__tmp->type))__val = \
				(__is_kfifo_ptr(__tmp) ? \
				((typeof(__tmp->type))__kfifo->data) : \
				(__tmp->buf) \
				)[__kfifo->out & __tmp->kfifo.mask]; \
			smp_wmb(); \
			__kfifo->out++; \
		} \
	} \
	__ret; \
}) \
)

从队列中获取一个元素;

/**
 * kfifo_in - put data into the fifo
 * @fifo: address of the fifo to be used
 * @buf: the data to be added
 * @n: number of elements to be added
 *
 * This macro copies the given buffer into the fifo and returns the
 * number of copied elements.
 *
 * Note that with only one concurrent reader and one concurrent
 * writer, you don't need extra locking to use these macro.
 */
#define	kfifo_in(fifo, buf, n) \
({ \
	typeof((fifo) + 1) __tmp = (fifo); \
	typeof(__tmp->ptr_const) __buf = (buf); \
	unsigned long __n = (n); \
	const size_t __recsize = sizeof(*__tmp->rectype); \
	struct __kfifo *__kfifo = &__tmp->kfifo; \
	(__recsize) ?\
	__kfifo_in_r(__kfifo, __buf, __n, __recsize) : \
	__kfifo_in(__kfifo, __buf, __n); \
})

入队操作;

/**
 * kfifo_out - get data from the fifo
 * @fifo: address of the fifo to be used
 * @buf: pointer to the storage buffer
 * @n: max. number of elements to get
 *
 * This macro get some data from the fifo and return the numbers of elements
 * copied.
 *
 * Note that with only one concurrent reader and one concurrent
 * writer, you don't need extra locking to use these macro.
 */
#define	kfifo_out(fifo, buf, n) \
__kfifo_uint_must_check_helper( \
({ \
	typeof((fifo) + 1) __tmp = (fifo); \
	typeof(__tmp->ptr) __buf = (buf); \
	unsigned long __n = (n); \
	const size_t __recsize = sizeof(*__tmp->rectype); \
	struct __kfifo *__kfifo = &__tmp->kfifo; \
	(__recsize) ?\
	__kfifo_out_r(__kfifo, __buf, __n, __recsize) : \
	__kfifo_out(__kfifo, __buf, __n); \
}) \
)
出队操作;
/**
 * kfifo_in_spinlocked - put data into the fifo using a spinlock for locking
 * @fifo: address of the fifo to be used
 * @buf: the data to be added
 * @n: number of elements to be added
 * @lock: pointer to the spinlock to use for locking
 *
 * This macro copies the given values buffer into the fifo and returns the
 * number of copied elements.
 */
#define	kfifo_in_spinlocked(fifo, buf, n, lock) \
({ \
	unsigned long __flags; \
	unsigned int __ret; \
	spin_lock_irqsave(lock, __flags); \
	__ret = kfifo_in(fifo, buf, n); \
	spin_unlock_irqrestore(lock, __flags); \
	__ret; \
})
入队一个操作,使用自旋锁上锁,加入队列后解开自旋锁;




linux 内核 队列 kfifo 在模块里尝试自己实现了个队列, 在多进程(内核里应该叫做多线程吧)操作时会出问题。 也曾尝试解决遇到的问题,但由于自己内核开发功夫上签,最终还是失败了 .... 后来还是采取了内核的实现 kfifo(include/linux/kfifo.h), kfifo在 linux 标准内核>=2.6.10 添加, 这里标准内核是因为 RHEL4.8 的内核版本是2.6.9(小于2.6.10)但是也有此 阅读详情

相关推荐

记录 环形缓冲区RingBuffer实现(基于Linux内核Kfifo)

基于LInux内核的Kfifo, 修改封装为缓存区类

周小哥的博客 1512

kfifo Introduction

FIFO简介 FIFO就是先进先出的意思,一般用队列表示,Linux Kernel实现了一个通用的FIFO, 称之为kfifo。本文参照linux-kernel-3.19的代码,由于代码相对于老的接口有一些变动, 所以对于用户来说需要作出如下一些更变。将类型声明由 struct kfifo * 变为 struct kfifo 使用 kfifo_alloc() 或 kfifo_init() 初始化

Aming_world的专栏 2603

kfifo的demo代码

linux底层提取 ,最近项目中用到一个环形缓冲区(ring buffer),代码是由linux内核的kfifo改过来的。缓冲区在文件系统中经常用到,通过缓冲区缓解cpu读写内存和读写磁盘的速度。

Linux内核数据结构 —— 无锁环形队列 ( kfifo )

Linux内核数据结构 —— 无锁环形队列 ( kfifo )

qq_23174771的博客 7533

NAT反向代理技术的实现(外网访问内网)

NAT反向代理技术的实现(外网访问内网)(版权所有,引用 请联系作者,注明出处) NAT技术是网络中的重要应用之一。当有一个场景:内网搭建了服务器,需要外网访问时,可以借助NAT映射来实现。如:单位建立了一个Web服务器,我们希望在员工回家之后,依然可以访问到它,那怎么实现呢? 下面的拓扑图,就用来示范这个应用反面场景的实现过程。 一、题目要求: 地址配置如图。使用静态路由: 1、配置右侧交换机2950T,实现单臂路由; 2、配置路由使网络连通; 3、配置NAT访问,实现外网对风网服务器的

joyousmime的博客 8491

wincc 服务器授权型号,WinCC V7.5 SP1软件安装及授权方法

上篇教程给大家介绍了TIA Portal V16 安装方法,今天分享一下WinCC V7.5 SP1。目前V7.5 SP1是WinCC最新的版本,发布时间2019年11月13日。先放一个官网对WinCC V7.5 的介绍视频,感兴趣的可以先看一下。1、软件下载官网下载链接:https://support.industry.siemens.com/cs/document/109772879五个文件下...

weixin_39956110的博客 1万+

利用Linux内核KFIFO代码,实现大量数据的写入与读出

参考Linux内核中的kfifo.h文件,进行简单修改以便使用,使用两个线程,其中一个线程(如Pthread_Write)进行写操作,另个一线程(如Pthread_Read)进行读操作;其中写入连续数字,读出的数据可以写入到一个文件中,但是读出的数据必须是连续的,数据个数60亿,期间不适用加锁机制; ring_buffer.h文件: #ifndef KFIFO_HEADER_H  #defi

sinat_25376319的博客 1725

Multisim仿真运放积分器踩坑实录:为什么你的方波变不成三角波?

本文针对Multisim仿真运放积分器时方波无法转换为三角波的常见问题,提供了详细的排查与调试指南。文章指出,经典RC积分电路因直流反馈开路导致运放饱和,核心解决方案是在反馈电容两端并联大阻值电阻以稳定直流工作点。通过参数优化(调整Rin、C、Rf)和高级仿真技巧,手把手教你调出线性度好、幅度适中的完美三角波,并分享异常波形(如饱和、不对称、振荡)的对应策略。

weixin_29231263的博客 115

Linux内核中bytestream kfifo学习

定义kfifo结构体 #define __STRUCT_KFIFO_COMMON(datatype, recsize, ptrtype) \ union { \ struct __kfifo kfifo; \ datatype *type; \ const datatype *const_type; \ char (*rectype)[recsize]; \ ptrtype *ptr; \ ptrtype const *ptr_const; \ } #define .

sjxpf922的博客 1171

5、数据库基础概念与数据建模全解析

本文深入解析了数据库的基础概念,包括函数依赖、决定因素和多值依赖等关键依赖关系,同时探讨了数据建模的重要方法论,如IDEF1X、信息工程和陈方法。此外,还介绍了SQL Server管理工作室的图表功能,帮助用户进行数据库的可视化设计。通过本文,读者将掌握数据库设计的核心知识,为构建高效、可扩展的数据库系统奠定基础。

81

高通平台N4单路输入的720P相机预览

N4的一路720P Camera作为MIPI摄像头使用

llw21680的专栏 165

循环队列kfifo

kfifo是内核里面的一个First In First Out数据结构,它采用环形循环队列的数据结构来实现;它提供一个无边界的字节流服务,最重要的一点是,它使用并行无锁编程技术,即当它用于只有一个入队线程和一个出队线程的场情时,两个线程可以并发操作,而不需要任何加锁行为,就可以保证kfifo的线程安全。kfifo代码既然肩负着这么多特性,那我们先一敝它的代码:structkfifounsignedcharbuffer;

myPhilia的博客 261

Python 爬虫 + 数据分析:社会调查数据抓取与结果可视化分析

在当今数字化时代,数据已成为推动社会发展的关键资源之一。无论是市场调研、学术研究还是政策制定,社会调查数据都扮演着至关重要的角色。通过 Python 爬虫技术,我们可以高效地获取这些数据,并结合数据分析与可视化工具,深入挖掘数据背后的价值。本文将通过一个完整的实战项目,带你掌握如何使用 Python 爬虫抓取社会调查数据,并进行可视化分析。

yansideyucsdn的博客 126

眉目传情之匠心独运的kfifo

学不考儒,务掇精华;文不按古,匠心独运。Linux kernal 鬼斧神工,博大精深,让人叹为观止,拍手叫绝。然匠心独运的设计并非扑朔迷离、盘根错节,真正的匠心独运乃辞简理博、化繁为简,在简洁中昭显优雅和智慧,kfifo就是这样一种数据结构,它就是这样简约高效,匠心独运,妙不可言,下面就跟大家一起探讨学习。

@Echo· 个人技术笔记 2万+

【AIGC】Qwen3-Embedding:Embedding与Rerank模型新标杆

Qwen3-Embedding:文本嵌入与重排序模型的技术解析与应用实践

一个内容严谨、方向前沿、极具实践价值的AI大模型技术分享站 3102

代谢组数据分析(二十一):通过MetaboAnalystR标准化构建sPLSDA预测模型

本文介绍了如何使用R语言中的MetaboAnalystR包和mixOmics包进行代谢组学数据的标准化和sPLSDA分析。MetaboAnalystR包用于数据预处理,包括数据初始化、清洗、补足、过滤和标准化等步骤,以确保数据质量。mixOmics包则用于sPLSDA分析,通过Lasso惩罚进行变量选择,并建立分类模型。文章详细说明了安装和加载相关R包的步骤,并提供了数据导入和预处理的代码示例。最后,强调了数据预处理的重要性,以确保后续分析的准确性和可靠性。

专注生信领域 2431

Linux内核数据结构kfifo详解

Linux kernal 鬼斧神工,博大精深,让人叹为观止,拍手叫绝。然匠心独运的设计并非扑朔迷离、盘根错节,真正的匠心独运乃辞简理博、化繁为简,在简洁中昭显优雅和智慧,kfifo就是这样一种数据结构,它就是这样简约高效,匠心独运,妙不可言,下面就跟大家一起探讨学习。 一、kfifo概述 本文分析的原代码版本 2.6.32.63 kfifo的

zhipingxi的博客 1660

VB摄像头监控

该VB模块可对摄像头捕获的画面进行录像等,可在创建的窗口进行控制

Linux  内核并发无锁环形队列kfifo的原理和实现

前面在《Linux内核数据结构kfifo详解》一文中详细解析了 Linux  内核并发无锁环形队列kfifo的原理和实现,kfifo鬼斧神工,博大精深,让人叹为观止,但遗憾的是kfifo为内核提供服务,并未开放出来。剑不试则利钝暗,弓不试则劲挠诬,鹰不试则巧拙惑,马不试则良驽疑,光说不练是不能学到精髓的,下面就动手实现自己的并发无锁队列UnlockQueue(单生产者单消费者)。 一、Unloc...

随意的风的专栏 3908

C# WinForm 基于DirectShow.dll编写的程序,可边预览边保存视频,音频和图片

基于微软的DirectShow.dll的二次开发1.自动识别连接的摄像头跟麦克风且可以对其进行选择(默认选中第一个)2.可录制wmv和avi两种格式的视频并且都带有音频,avi可以录制的分辨率和帧数进行选择,wmv默认进行了淸晰度优化如不喜欢可去除代码中有相关提示3.可在预览点开之后进行拍照,也可边录制视频边拍照4.添加了视频和音频的压缩功能(酌情使用)这次二次开发发现C#对DirectShow的相关信息太少,这次做完也不敢藏私共享出来,还望大家指正

老版QQ原生表情gif动态

这是老版的QQ表情,不过全是动态的的,Windows照片查看器是不会动的,可以右击用浏览器打开查看,再说一遍是老版的,只是分享给宁愿用老版也要动态的人。

【Linux】无锁队列kfifo --研读(适合一读一写线程并发操作)

计算机科学家已经证明,当只有一个读线程和一个写线程并发操作时,不需要任何额外的锁,就可以确保是线程安全的,也即kfifo使用了无锁编程技术,以提高kernel的并发。 原文:巧夺天工的kfifo(修订版) https://blog.csdn.net/linyt/article/details/53355355 Linux kernel里面从来就不缺少...

小鱼菜鸟的博客 588

假人有限元模型

假人模型,车辆碰撞假人有限元模型,适合做乘员安全的研究者利用

FIFO - linux内核数据结构

Linux kernal 鬼斧神工,博大精深,让人叹为观止,拍手叫绝。然匠心独运的设计并非扑朔迷离、盘根错节,真正的匠心独运乃辞简理博、化繁为简,在简洁中昭显优雅和智慧,kfifo就是这样一种数据结构,它就是这样简约高效,匠心独运,妙不可言,下面就跟大家一起探讨学习。 一、kfifo概述 本文分析的原代码版本 2.6.32.63 kfifo的头文件 include/linux/kfifo.h kfifo的源文件 kernel/kfifo.c kfifo是一种"First

生活需要深度 1130

【Linux】巧夺天工的kfifo(修订版) --研读

原文:https://blog.csdn.net/linyt/article/details/53355355 Linux kernel里面从来就不缺少简洁,优雅和高效的代码,只是我们缺少发现和品味的眼光。在Linux kernel里面,简洁并不表示代码使用神出鬼没的超然技巧,相反,它使用的不过是大家非常熟悉的基础数据结构,但是kernel开发者能从基...

小鱼菜鸟的博客 156

奥格尔巧妙kfifo

奥格尔巧妙kfifo Author:Echo Chen(陈斌) Email:chenb19870707@gmail.com Blog:Blog.csdn.net/chen19870707 Date:October 8th, 2014       学不考儒,务掇精华。文不按古,匠心独运。Linux kernal 鬼斧神工,博大精深。让人叹为观止。...

weixin_34365635的博客 170

java环形队列并发_并发无锁环形队列的实现

前面在《Linux内核数据结构kfifo详解》一文中详细解析了 Linux 内核并发无锁环形队列kfifo的原理和实现,kfifo鬼斧神工,博大精深,让人叹为观止,但遗憾的是kfifo为内核提供服务,并未开放出来。剑不试则利钝暗,弓不试则劲挠诬,鹰不试则巧拙惑,马不试则良驽疑,光说不练是不能学到精髓的,下面就动手实现自己的并发无锁队列UnlockQueue(单生产者单消费者)。一、UnlockQ...

weixin_39938165的博客 203

linux内核数据结构二叉树,Linux 内核设计与实现 — 内核数据结构

8种机械键盘轴体对比本人程序员,要买一个写代码的键盘,请问红轴和茶轴怎么选?本章节的内容是一些数据结构,没甚么可说的。随便记记笔记吧。内容包括链表、队列、映射、二叉树。链表这是 linux 中最简单的数据结构,是一种存放客可变数量元素的数据结构。具体的就是用指针将元素连接起来。具体的定义就看数据结构书吧,这里主要讲 linux 下的实现。Linux 链表的实现链表的数据结构struct list...

weixin_36081485的博客 379
上一篇: 字符设备驱动程序
下一篇: malloc 实现二维数组
zmrlinux
博客等级 码龄12年 409粉丝 327原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符  | 博主筛选后可见
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值