我的站点

一个系统软件工程师的随手涂鸦

Date: 八月 24, 2015

Linux kernel 笔记 (16)——clflush_cache_range函数

/**
 * clflush_cache_range - flush a cache range with clflush
 * @vaddr:  virtual start address
 * @size:   number of bytes to flush
 *
 * clflushopt is an unordered instruction which needs fencing with mfence or
 * sfence to avoid ordering issues.
 */
void clflush_cache_range(void *vaddr, unsigned int size)
{
    void *vend = vaddr + size - 1;

    mb();

    for (; vaddr < vend; vaddr += boot_cpu_data.x86_clflush_size)
        clflushopt(vaddr);
    /*
     * Flush any possible final partial cacheline:
     */
    clflushopt(vend);

    mb();
}

clflush_cache_range()函数用来把从虚拟地址vaddr起始的,长度为size的的cache line置为无效,各级包含这个cache linecache系统都会失效。

Linux kernel 笔记 (15)——ioremap函数

ioremap用来把physical memory映射到kernel virtual address space,常用于把设备的I/O memory address映射到kernel virtual address space

Git object 类型笔记

Git objectsgit的实际存储数据,是git repository的重要组成部分,也是不可改变的。所有的git objects都存储在Git Object Database。每个object都是压缩(使用Zlib)的,通过内容的SHA-1值和一个头可以访问(Each object is compressed (with Zlib) and referenced by the SHA-1 value of its contents plus a small header.)。

(1)The Blob
Git中的文件内容存储成blob(要注意是内容,不是文件。文件的名字和模式不存储在blob。因此如果两个文件内容相同,则只会存储一份blob):

1

 

2

(2)The Tree
Git中的文件夹对应为treeTree中含有这个tree包含的blobtree的名字,模式,类型和SHA等信息:

3

4

(3)The Commit
Commit非常简单,只是指向了一个tree,并且包含了作者,提交者,提交信息,和所有的直属parent commit

5

6

(4)The Tag
Tag为某个commit提供了一个永久的shorthand name,它包含object、类型、tagtag作者和tag信息:

7

参考资料:
Git internals

Lua笔记(15)—— “Lua Closures and Iterators”读书笔记

这篇是Lua Closures and Iterators的读书笔记:

(1)Closure有以下属性:

a) A function inside a function;
b) The inner function can see local variables of the outer function.

利用closure可以实现下列feature

a) Iterators;
b) OOP class like devices.

(2)Iterators and For Loops

代码示例:

#!/usr/bin/lua

function positive_integers(max)
    local n = 0
    return function()
        n = n + 1
        if n > max then
            return nil
        else
            return n
        end
    end
end

for v in positive_integers(3) do
    print(v)
end

Iterator含义如下:

An iterator is a function inside a function where the inner function sees the outer function's local variables. The inner function does something to increment or cycle through the local variable(s) in the outer function, returning the new value of the outer function's local variable, or something depending on that new value. The outer function passes the inner function back as a function return.

在上面例子中,iterator就是positive_integers()返回的匿名函数。

Generic for既不作用在iterator函数的返回值上,也不作用在iterator make函数上(positive_integers),而是作用在iterator函数上。

Powered by WordPress & Theme by Anders Norén