ALSA学习(2)——pcm设备逻辑

这篇具有很好参考价值的文章主要介绍了ALSA学习(2)——pcm设备逻辑。希望对大家有所帮助。如果存在错误或未考虑完全的地方,请大家不吝赐教,您也可以点击"举报违法"按钮提交疑问。


参考学习地址: https://www.cnblogs.com/jason-lu/archive/2013/06/07/3123750.html

一、pcm简介

PCM是英文Pulse-code modulation的缩写,中文译名是脉冲编码调制.我们知道在现实生活中,人耳听到的声音是模拟信号,PCM就是要把声音从模拟转换成数字信号的一种技术,他的原理简单地说就是利用一个固定的频率对模拟信号进行采样,采样后的信号在波形上看就像一串连续的幅值不一的脉冲,把这些脉冲的幅值按一定的精度进行量化,这些量化后的数值被连续地输出、传输、处理或记录到存储介质中,所有这些组成了数字音频的产生过程.
ALSA学习(2)——pcm设备逻辑
PCM信号的两个重要指标是采样频率和量化精度,目前,CD音频的采样频率通常为44100Hz,量化精度是16bit.
你的采样频率越高,你通过ad模块播放出的声音还原度就越高。

过程大概就是
capture —>AD模块—>playback

1、playback 如何把用户空间的应用程序发过来的PCM数据,转化为人耳可以辨别的模拟音频
2、capture 把mic拾取到得模拟信号,经过采样、量化,转换为PCM信号送回给用户空间的应用程序

二、pcm结构详解

2.1 pcm框图

要访问PCM的中间层代码,你首先要包含头文件<sound/pcm.h>,另外,如果需要访问一些与 hw_param相关的函数,可能也要包含<sound/pcm_params.h>.
ALSA学习(2)——pcm设备逻辑

每个声卡最多可以包含4个pcm的实例,每个pcm实例对应一个pcm设备文件.pcm实例数量的这种限制源于linux设备号所占用的位大小,如果以后使用64位的设备号,我们将可以创建更多的pcm实例.不过大多数情况下,在嵌入式设备中,一个pcm实例已经足够了。
一个pcm实例由一个playback stream和一个capture stream组成,这两个stream又分别有一个或多个substreams(压缩层)组成。

2.2 pcm代码框架

在kernel/include/sound/pcm.h代码中有对应的源代码,这里贴一个框图帮助大家理解。

ALSA学习(2)——pcm设备逻辑

我们从中间位置开始分析
1、snd_pcm_substream是pcm中间层的核心,绝大部分任务都是在substream中处理,尤其是他的ops(snd_pcm_ops)字段,许多user空间的应用程序通过alsa-lib对驱动程序的请求都是由该结构中的函数处理。它的runtime字段则指向snd_pcm_runtime结构,snd_pcm_runtime记录这substream的一些重要的软件和硬件运行环境和参数。(后面有解析)
2、snd_pcm是挂在snd_card下面的一个snd_device
3、 snd_pcm_runtime结构,snd_pcm_runtime记录这substream的一些重要的软件和硬件运行环境和参数.
4、snd_pcm_str中的substream字段,指向snd_pcm_substream结构。
5、snd_pcm_substream是pcm中间层的核心,绝大部分任务都是在substream中处理,尤其是他的ops(snd_pcm_ops)字段,许多user空间的应用程序通过alsa-lib对驱动程序的请求都是由该结构中的函数处理.它的runtime字段则指向snd_pcm_runtime结构,snd_pcm_runtime记录这substream的一些重要的软件和硬件运行环境和参数。

下面是rk3288的pcm的对应的代码。其实就是通过这个结构体包含了很多各种接口。

struct snd_pcm_substream {
	struct snd_pcm *pcm;
	struct snd_pcm_str *pstr;
	void *private_data;		/* copied from pcm->private_data */
	int number;
	char name[32];			/* substream name */
	int stream;			/* stream (direction) */
	struct pm_qos_request latency_pm_qos_req; /* pm_qos request */
	size_t buffer_bytes_max;	/* limit ring buffer size */
	struct snd_dma_buffer dma_buffer;
	size_t dma_max;
	/* -- hardware operations -- */
	const struct snd_pcm_ops *ops;
	/* -- runtime information -- */
	struct snd_pcm_runtime *runtime;
        /* -- timer section -- */
	struct snd_timer *timer;		/* timer */
	unsigned timer_running: 1;	/* time is running */
	long wait_time;	/* time in ms for R/W to wait for avail */
	/* -- next substream -- */
	struct snd_pcm_substream *next;
	/* -- linked substreams -- */
	struct list_head link_list;	/* linked list member */
	struct snd_pcm_group self_group;	/* fake group for non linked substream (with substream lock inside) */
	struct snd_pcm_group *group;		/* pointer to current group */
	/* -- assigned files -- */
	void *file;
	int ref_count;
	atomic_t mmap_count;
	unsigned int f_flags;
	void (*pcm_release)(struct snd_pcm_substream *);
	struct pid *pid;
#if IS_ENABLED(CONFIG_SND_PCM_OSS)
	/* -- OSS things -- */
	struct snd_pcm_oss_substream oss;
#endif
#ifdef CONFIG_SND_VERBOSE_PROCFS
	struct snd_info_entry *proc_root;
	struct snd_info_entry *proc_info_entry;
	struct snd_info_entry *proc_hw_params_entry;
	struct snd_info_entry *proc_sw_params_entry;
	struct snd_info_entry *proc_status_entry;
	struct snd_info_entry *proc_prealloc_entry;
	struct snd_info_entry *proc_prealloc_max_entry;
#ifdef CONFIG_SND_PCM_XRUN_DEBUG
	struct snd_info_entry *proc_xrun_injection_entry;
#endif
#endif /* CONFIG_SND_VERBOSE_PROCFS */
	/* misc flags */
	unsigned int hw_opened: 1;
};

看框图指向下面的那个箭头。最重要的snd_pcm_ops,这里面有很多的操作函数,open、close、hw_free、hw_params、trigger这些。

struct snd_pcm_ops {
	int (*open)(struct snd_pcm_substream *substream);
	int (*close)(struct snd_pcm_substream *substream);
	int (*ioctl)(struct snd_pcm_substream * substream,
		     unsigned int cmd, void *arg);
	int (*hw_params)(struct snd_pcm_substream *substream,
			 struct snd_pcm_hw_params *params);
	int (*hw_free)(struct snd_pcm_substream *substream);
	int (*prepare)(struct snd_pcm_substream *substream);
	int (*trigger)(struct snd_pcm_substream *substream, int cmd);
	snd_pcm_uframes_t (*pointer)(struct snd_pcm_substream *substream);
	int (*get_time_info)(struct snd_pcm_substream *substream,
			struct timespec *system_ts, struct timespec *audio_ts,
			struct snd_pcm_audio_tstamp_config *audio_tstamp_config,
			struct snd_pcm_audio_tstamp_report *audio_tstamp_report);
	int (*fill_silence)(struct snd_pcm_substream *substream, int channel,
			    unsigned long pos, unsigned long bytes);
	int (*copy_user)(struct snd_pcm_substream *substream, int channel,
			 unsigned long pos, void __user *buf,
			 unsigned long bytes);
	int (*copy_kernel)(struct snd_pcm_substream *substream, int channel,
			   unsigned long pos, void *buf, unsigned long bytes);
	struct page *(*page)(struct snd_pcm_substream *substream,
			     unsigned long offset);
	int (*mmap)(struct snd_pcm_substream *substream, struct vm_area_struct *vma);
	int (*ack)(struct snd_pcm_substream *substream);
};
  1. open函数为PCM模块设定支持的传输模式、数据格式、通道数、period等参数,并为playback/capture stream分配相应的DMA通道。
  2. hw_params函数为substream(每打开一个playback或capture,ALSA core均产生相应的一个substream)设定DMA的源(目的)地址,以及DMA缓冲区的大小。
  3. 当pcm“准备好了”调用该函数。在这里根据channels、buffer_bytes等来设定DMA传输参数,跟具体硬件平台相关。注:每次调用snd_pcm_prepare()的时候均会调用prepare函数。
  4. 当pcm开始、停止、暂停的时候都会调用trigger函数。
  5. snd_pcm_runtime函数说明:我们会留意到ops各成员函数均需要取得一个snd_pcm_runtime结构体指针,这个指针可以通过substream->runtime来获得。snd_pcm_runtime是pcm运行时的信息。当打开一个pcm子流时,pcm运行时实例就会分配给这个子流。它拥有很多信息:hw_params和sw_params配置拷贝,缓冲区指针,mmap记录,自旋锁等。snd_pcm_runtime对于驱动程序操作集函数是只读的,仅pcm中间层可以改变或更新这些信息

hw_params对应的代码

static int s3c_pcm_hw_params(struct snd_pcm_substream *substream,
                           struct snd_pcm_hw_params *params)
{
       struct snd_pcm_runtime *runtime = substream->runtime;
       int err = 0;
 
       snd_pcm_set_runtime_buffer(substream, &substream->dma_buffer);
       runtime->dma_bytes = params_buffer_bytes(params);
       return err;
}

trigger对应代码

static int s3c_pcm_trigger(struct snd_pcm_substream *substream, int cmd)
{
       struct runtime_data *prtd = substream->runtime->private_data;
       int ret = 0;
 
       spin_lock(&prtd->lock);
 
       switch (cmd) {
       case SNDRV_PCM_TRIGGER_START:
       case SNDRV_PCM_TRIGGER_RESUME:
       case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
              prtd->state |= ST_RUNNING;
              dma_ctrl(prtd->params->channel, DMAOP_START); //DMA开启
              break;
 
       case SNDRV_PCM_TRIGGER_STOP:
       case SNDRV_PCM_TRIGGER_SUSPEND:
       case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
              prtd->state &= ~ST_RUNNING;
              dma_ctrl(prtd->params->channel, DMAOP_STOP); //DMA停止
              break;
 
       default:
              ret = -EINVAL;
              break;
       }
 
       spin_unlock(&prtd->lock);
 
       return ret;
}

代码中的dma_buffer是DMA缓冲区,它通过4个字段定义:dma_area、dma_addr、dma_bytes和dma_private。其中dma_area是缓冲区逻辑地址,dma_addr是缓冲区的物理地址,dma_bytes是缓冲区的大小,dma_private是ALSA的DMA管理用到的。dma_buffer是在pcm_new()中初始化的;当然也可以把分配dma缓冲区的工作放到这部分来实现,但考虑到减少碎片,故还是在pcm_new中以最大size(即buffer_bytes_max)来分配。

snd_pcm中有一个 struct snd_pcm_str streams[2];这两个元素分别代表playback stream和capture stream,可以看上图。这里面也有声卡,设备号等等。
snd_pcm对应的代码:

struct snd_pcm {
	struct snd_card *card;
	struct list_head list;
	int device; /* device number */
	unsigned int info_flags;
	unsigned short dev_class;
	unsigned short dev_subclass;
	char id[64];
	char name[80];
	struct snd_pcm_str streams[2];
	struct mutex open_mutex;
	wait_queue_head_t open_wait;
	void *private_data;
	void (*private_free) (struct snd_pcm *pcm);
	bool internal; /* pcm is for internal use only */
	bool nonatomic; /* whole PCM operations are in non-atomic context */
#if IS_ENABLED(CONFIG_SND_PCM_OSS)
	struct snd_pcm_oss oss;
#endif
};

snd_pcm_file对应代码:

struct snd_pcm_file {
	struct snd_pcm_substream *substream;
	int no_compat_mmap;
	unsigned int user_pversion;	/* supported protocol version */
};

snd_pcm_runtime代码

struct snd_pcm_runtime {
	/* -- Status -- */
	struct snd_pcm_substream *trigger_master;
	struct timespec trigger_tstamp;	/* trigger timestamp */
	bool trigger_tstamp_latched;     /* trigger timestamp latched in low-level driver/hardware */
	int overrange;
	snd_pcm_uframes_t avail_max;
	snd_pcm_uframes_t hw_ptr_base;	/* Position at buffer restart */
	snd_pcm_uframes_t hw_ptr_interrupt; /* Position at interrupt time */
	unsigned long hw_ptr_jiffies;	/* Time when hw_ptr is updated */
	unsigned long hw_ptr_buffer_jiffies; /* buffer time in jiffies */
	snd_pcm_sframes_t delay;	/* extra delay; typically FIFO size */
	u64 hw_ptr_wrap;                /* offset for hw_ptr due to boundary wrap-around */

	/* -- HW params -- */
	snd_pcm_access_t access;	/* access mode */
	snd_pcm_format_t format;	/* SNDRV_PCM_FORMAT_* */
	snd_pcm_subformat_t subformat;	/* subformat */
	unsigned int rate;		/* rate in Hz */
	unsigned int channels;		/* channels */
	snd_pcm_uframes_t period_size;	/* period size */
	unsigned int periods;		/* periods */
	snd_pcm_uframes_t buffer_size;	/* buffer size */
	snd_pcm_uframes_t min_align;	/* Min alignment for the format */
	size_t byte_align;
	unsigned int frame_bits;
	unsigned int sample_bits;
	unsigned int info;
	unsigned int rate_num;
	unsigned int rate_den;
	unsigned int no_period_wakeup: 1;

	/* -- SW params -- */
	int tstamp_mode;		/* mmap timestamp is updated */
  	unsigned int period_step;
	snd_pcm_uframes_t start_threshold;
	snd_pcm_uframes_t stop_threshold;
	snd_pcm_uframes_t silence_threshold; /* Silence filling happens when
						noise is nearest than this */
	snd_pcm_uframes_t silence_size;	/* Silence filling size */
	snd_pcm_uframes_t boundary;	/* pointers wrap point */

	snd_pcm_uframes_t silence_start; /* starting pointer to silence area */
	snd_pcm_uframes_t silence_filled; /* size filled with silence */

	union snd_pcm_sync_id sync;	/* hardware synchronization ID */

	/* -- mmap -- */
	struct snd_pcm_mmap_status *status;
	struct snd_pcm_mmap_control *control;

	/* -- locking / scheduling -- */
	snd_pcm_uframes_t twake; 	/* do transfer (!poll) wakeup if non-zero */
	wait_queue_head_t sleep;	/* poll sleep */
	wait_queue_head_t tsleep;	/* transfer sleep */
	struct fasync_struct *fasync;

	/* -- private section -- */
	void *private_data;
	void (*private_free)(struct snd_pcm_runtime *runtime);

	/* -- hardware description -- */
	struct snd_pcm_hardware hw;
	struct snd_pcm_hw_constraints hw_constraints;

	/* -- timer -- */
	unsigned int timer_resolution;	/* timer resolution */
	int tstamp_type;		/* timestamp type */

	/* -- DMA -- */           
	unsigned char *dma_area;	/* DMA area */
	dma_addr_t dma_addr;		/* physical bus address (not accessible from main CPU) */
	size_t dma_bytes;		/* size of DMA area */

	struct snd_dma_buffer *dma_buffer_p;	/* allocated buffer */

	/* -- audio timestamp config -- */
	struct snd_pcm_audio_tstamp_config audio_tstamp_config;
	struct snd_pcm_audio_tstamp_report audio_tstamp_report;
	struct timespec driver_tstamp;

#if IS_ENABLED(CONFIG_SND_PCM_OSS)
	/* -- OSS things -- */
	struct snd_pcm_oss_runtime oss;
#endif
};

三、pcm声卡创建

pcm声卡创建框图
ALSA学习(2)——pcm设备逻辑

从这框图我们已经可以理解到整个pcm创建的逻辑。

  1. 当我的驱动想要去创建一个声卡的时候,就回去调用在init函数里面的snd_card_create函数(snd_card_new)这是根据linux内核版本来命名的,这样就会产生一个声卡
  2. 创建pcm设备,并把声卡加入进去,去调用pcm.c里面的snd_pcm_new函数,
 int snd_pcm_new(struct snd_card *card, const char *id, int device,
		int playback_count, int capture_count, struct snd_pcm **rpcm)
{
	return _snd_pcm_new(card, id, device, playback_count, capture_count,
			false, rpcm);
}
EXPORT_SYMBOL(snd_pcm_new);

同事还会去调用里面函数进行pcm流的创建和pcm设备的相关个工作。

  1. 然后去snd_pcm_set_ops设置操作该pcm的控制/操作接口函数,参数中的snd_pcm_ops结构中的函数通常就是我们驱动要实现的函数。
  2. 最后就是注册声卡,创建设备节点snd_card_register(),在这个阶段会遍历声卡下的所有逻辑设备,并且调用各设备的注册回调函数,回调函数建立了和用户空间应用程序(alsa-lib)通信所用的设备文件节点:/dev/snd/pcmCxxDxxp和/dev/snd/pcmCxxDxxc
  3. 然后在内核加载中就会去加载声卡的模块。

创建声卡的函数已经在kernel/include/sound/pcm.h里面预留了接口:

int snd_pcm_new(struct snd_card *card, const char *id, int device,
		int playback_count, int capture_count,
		struct snd_pcm **rpcm);
  1. 前面两个我理解为声卡的名字和id号.
  2. 参数device 表示目前创建的是该声卡下的第几个pcm,第一个pcm设备从0开始.
  3. 参数playback_count 表示该pcm将会有几个playback substream,capture_count表示该pcm将会有几个capture substream。
  4. 这个二级指针暂时不知道有什么用。
    同时还设置了一个设置pcm的函数接口
void snd_pcm_set_ops(struct snd_pcm * pcm, int direction,
		     const struct snd_pcm_ops *ops);

四、设备文件节点建立

前面说了如何去创建一个pcm声卡,这里说一下如何去创建一个声卡下面的设备节点。
其实上面那个框图最后的snd_pcm_dev_register函数就已经在创建声卡了.
函数原型:

static int snd_pcm_dev_register(struct snd_device *device)
{
	int cidx, err;
	struct snd_pcm_substream *substream;
	struct snd_pcm *pcm;
	if (snd_BUG_ON(!device || !device->device_data))
		return -ENXIO;
	pcm = device->device_data;

	mutex_lock(&register_mutex);
	err = snd_pcm_add(pcm);
	if (err)
		goto unlock;
	for (cidx = 0; cidx < 2; cidx++) {
		int devtype = -1;
		if (pcm->streams[cidx].substream == NULL)
			continue;
		switch (cidx) {
		case SNDRV_PCM_STREAM_PLAYBACK:
			devtype = SNDRV_DEVICE_TYPE_PCM_PLAYBACK;
			break;
		case SNDRV_PCM_STREAM_CAPTURE:
			devtype = SNDRV_DEVICE_TYPE_PCM_CAPTURE;
			break;
		}
		/* register pcm */
		err = snd_register_device(devtype, pcm->card, pcm->device,
					  &snd_pcm_f_ops[cidx], pcm,
					  &pcm->streams[cidx].dev);
		if (err < 0) {
			list_del_init(&pcm->list);
			goto unlock;
		}

		for (substream = pcm->streams[cidx].substream; substream; substream = substream->next)
			snd_pcm_timer_init(substream);
	}

	pcm_call_notify(pcm, n_register);

 unlock:
	mutex_unlock(&register_mutex);
	return err;
}

4.1 snd_minor 保存信息

snd_minor 结构体保存了声卡下某个逻辑设备的上下文信息,它在逻辑设备建立阶段被填充,在逻辑设备被使用时就可以从该结构体中得到相应的信息。pcm设备也不例外,也需要使用该结构体。该结构体在 include/sound/core.h 中定义。

struct snd_minor {
	int type;			/* SNDRV_DEVICE_TYPE_XXX */
	int card;			/* card number */
	int device;			/* device number */
	const struct file_operations *f_ops;	/* file operations */
	void *private_data;		/* private data for f_ops->open */
	struct device *dev;		/* device for sysfs */
	struct snd_card *card_ptr;	/* assigned card instance */
};

上面声卡注册阶段就已经说了一个函数用于调用

		/* register pcm */
		err = snd_register_device(devtype, pcm->card, pcm->device,
					  &snd_pcm_f_ops[cidx], pcm,
					  &pcm->streams[cidx].dev);

我们再回到snd_register_device这个函数里(kernel/sound/core/sound.c)文章来源地址https://www.toymoban.com/news/detail-411493.html

int snd_register_device(int type, struct snd_card *card, int dev,
			const struct file_operations *f_ops,
			void *private_data, struct device *device)
{
	int minor;
	int err = 0;
	struct snd_minor *preg;

	if (snd_BUG_ON(!device))
		return -EINVAL;

	preg = kmalloc(sizeof *preg, GFP_KERNEL);
	if (preg == NULL)
		return -ENOMEM;
	preg->type = type;
	preg->card = card ? card->number : -1;
	preg->device = dev;
	preg->f_ops = f_ops;
	preg->private_data = private_data;
	preg->card_ptr = card;
	mutex_lock(&sound_mutex);
	minor = snd_find_free_minor(type, card, dev);
	if (minor < 0) {
		err = minor;
		goto error;
	}

	preg->dev = device;
	device->devt = MKDEV(major, minor);
	err = device_add(device);
	if (err < 0)
		goto error;

	snd_minors[minor] = preg;
 error:
	mutex_unlock(&sound_mutex);
	if (err < 0)
		kfree(preg);
	return err;
}
EXPORT_SYMBOL(snd_register_device);

  1. 首先,分配并初始化一个snd_minor结构中的各字段
    type:SNDRV_DEVICE_TYPE_PCM_PLAYBACK/SNDRV_DEVICE_TYPE_PCM_CAPTURE
    card:card的编号
    device:pcm实例的编号,大多数情况为0
    f_ops:snd_pcm_f_ops
    private_data:指向该pcm的实例
    
  2. 根据type,card和pcm的编号,确定数组的索引值minor,minor也作为pcm设备的次设备号
  3. 把该snd_minor结构的地址放入全局数组snd_minors[minor]中,在/kernel/sound/core/sound.c中定义了一个snd_minor指针的全局数组
static struct snd_minor *snd_minors[SNDRV_OS_MINORS];
  1. 最后,调用device_create创建设备节点

到了这里,关于ALSA学习(2)——pcm设备逻辑的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处: 如若内容造成侵权/违法违规/事实不符,请点击违法举报进行投诉反馈,一经查实,立即删除!

领支付宝红包 赞助服务器费用

相关文章

  • 如何查看声卡、pcm设备以及tinyplay、tinymix、tinycap的使用 Android tinyAlsa命令详解:

    1、查看当前的声卡: cat /proc/asound/cards 2、查看pcm设备列表: cat /proc/asound/pcm 3、查看当前有哪些进程占用了pcm设备节点 lsof |grep pcm     4、查看有哪些音频设备节点 ls /dev/snd/ 音频设备的命名规则为 [device type] C [card index] D [device index][capture/playback] ,即名字中含有4部分的信息

    2024年02月02日
    浏览(38)
  • ALSA框架学习笔记3:声卡注册流程(代码解析)

    以Amlogic V918D为例,介绍驱动如何将设备树中的声卡节点注册为声卡设备 一、设备树中的声卡节点 声卡名为\\\"AML-AUGESOUND\\\",下面有8个dai-link,每一个dai-link下面都有cpu dai和codec dai设备节点。每个dai-link都会被注册为一个pcm设备,这里先列出简化的流程: 从上一遍文章知道cpu da

    2024年02月16日
    浏览(27)
  • 数字逻辑与数字系统设计(袁小平)慕课参考答案

    第 1 讲 绪论 第 1 讲 绪论-单元测试 1、 问题:现代电子技术的发展,目前集成电路器件处于()阶段。 选项: A:分立元器件 B:集成电路 C:大规模集成电路 D:超大规模集成电路 答案: 【超大规模集成电路】 2、 问题:现代电子技术的发展,处于()阶段。 选项: A:理论奠基 B:分

    2024年02月04日
    浏览(26)
  • 快速挖掘设备逻辑洞方法分享

    接触 iot 也快有一年的时间了,一年来也挖掘了大大小小几十个洞,虽然能有些产出但是却逐渐对人工审计感到无趣和疲惫。在此之间我也尝试过通过使用 污点分析 , fuzz 等方法去进行自动化漏洞挖掘,但总因为目标不明确而导致挖掘效果不是很好。于是就产生了写一款可以

    2024年02月02日
    浏览(19)
  • 动态规划(用空间换时间的算法)原理逻辑代码超详细!参考自《算法导论》

    本篇博客以《 算法导论 》第15章动态规划算法为本背景,大量引用书中内容和实例,并根据书中伪代码给出python 代码复现 ,详解算法的 核心逻辑 和实现过程。 动态规划(Dynamic Programming)算法的核心思想是:将大问题划分为重叠的子问题进行解决,从而一步步获取最优解的处

    2024年01月16日
    浏览(47)
  • 《操作系统》逻辑地址如何转换为物理地址

    (1)十六进制 逻辑地址=页号+页内地址 物理地址=块号+页内地址 (2)非十六进制 物理地址=块号*页内大小+页内地址 页号=逻辑地址/页面大小字节=(取整数) 页内地址=逻辑地址%页面大小字节=(取余数) (1)十六进制 例题 一分页存储管理系统中逻辑地址长度为16位,页面

    2024年02月04日
    浏览(35)
  • 2.3.1操作系统-存储管理:页式存储、逻辑地址、物理地址、物理地址逻辑地址之间的地址关系、页面大小与页内地址长度的关系、缺页中断、内存淘汰规则

    在存储管理当中,操作系统会负责将外存的一些文件调入到内存当中,以便给CPU调用,如果调用的内容不在内存当中,那么会产生一种中断,叫做缺页中断。然后从外存调数据,调完数据再返回,接着访问之前的断点部分。 在调用的过程当中,如果是一个几十G的文件,调入

    2024年02月03日
    浏览(33)
  • 块设备调用逻辑(linux 5.4)

    2024年02月10日
    浏览(22)
  • 云上网络规划CIDR地址划分的参考示例

    CIDR规则 用例表示 功能 CIDR/网段 二进制 北京预发环境VPC子网 172. 17 . 0 .0/19 1010 1100 .[0001 0001] . [000] [00000].[0000 0000] 上海线上环境可用区B vSwitch 172.18. 1 .0/24 1010 1100 .[0001 0010] . [000] [00001] . [0000 0000] 上海线上环境可用区B vSwitch某台ECS机器 172.18.1. 2 1010 1100 .[0001 0010] . [000] [00001] .

    2024年02月03日
    浏览(16)
  • Java入门高频考查算法逻辑基础知识3-编程篇(超详细18题1.8万字参考编程实现)

    准备这些面试题时,请考虑如下准备步骤: 理解问题并澄清任何可能的疑点。确保你了解了面试官的期望,包括问题限制条件和期望的解决方案。 如果可能且适用的话,尝试先给出一个简单的解决方案,比如暴力法,然后再逐步优化它。 在优化之前,先分析暴力解法的效率

    2024年01月18日
    浏览(51)

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

博客赞助

微信扫一扫打赏

请作者喝杯咖啡吧~博客赞助

支付宝扫一扫领取红包,优惠每天领

二维码1

领取红包

二维码2

领红包