Lua笔记(17)—— 什么是chunk?

Pil中,chunk的定义:

Each piece of code that Lua executes, such as a file or a single line in interactive mode, is called a chunk. A chunk is simply a sequence of commands (or statements).

Lua执行的一段代码,无论是一个Lua文件,或者仅仅是一条语句,均统称为chunk。说白了,chunk就是一段语句(statement)。

Lua笔记(16)——全局变量和“local”变量

执行以下Lua代码:

i = 32
local i = 0
f = load("i = i + 1; print(i)")
g = function () i = i + 1; print(i) end
f() --> 33
g() --> 1

f()输出33g()输出1。原因是第一个i是全局变量,第二个ilocal变量,而同名的local变量总是覆盖掉全局变量。load产生的函数只能看到全局变量,因此f()输出33。如果想让g()函数访问全局变量i,可以利用全局环境变量_G

g = function () _G.i = _G.i + 1; print(_G.i) end
g() --> 34

Linux kernel 笔记 (17)——提交Linux Kernel IOMMU patch的注意事项

以下是提交Linux Kernel IOMMU patch的注意事项:

(1)Patch主题前缀:
IOMMU相关:<arch>/<iommu>
Intel VT-d相关:iommu/vt-d
举例如下:

iommu/vt-d: Enhance intel-iommu driver to support DMAR unit hotplug

(2)IOMMU patch每行不超过60个字符长度。

DMA Remapping —— DMA请求类型

Remapping硬件把来自设备的DMA内存访问请求分成两种类型:

(1)Requests without address-space-identifier:这是来自endpoint device的正常的内存访问请求,包括访问类型(读,写,原子访问),DMA地址和大小,发起请求的设备标示;

(2)Requests with address-space-identifier:这种内存访问请求会包含额外的信息:表明支持virtual memoryendpoint devicetargeted process address space。除了常规请求信息外,还有process address space identifier (PASID),扩展属性:Execute-Requested (ER) flag
(to indicate reads that are instruction fetches)
Privileged-mode-Requested (PR) flag (to distinguish user versus supervisor access))等等。

参考资料:
Intel ® Virtualization Technology for Directed I/O

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系统都会失效。

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函数上。

在RHEL系统上配置iso文件为yum源

RHEL不能联网时,可以配置安装RHELiso文件为yum源:

(1)挂载iso文件(以RHEL 7.0例):

mount RHEL-7.0-20140507.0-Server-x86_64-dvd1.iso /mnt/iso

(2)在/etc/yum.repos.d文件夹下创建一个RHEL.repo文件:

[RHEL]
name=rhel7server
baseurl=file:///mnt/iso/
enable=1
gpcheck=1
gpgkey=file:///mnt/iso/RPM-GPG-KEY-redhat-release 

P.S. iso文件只提供了一些必须的package。如果要安装的package不在iso中,就要配置相应版本的提供可选packageyum源:

# cat /etc/yum.repos.d/RHEL_OPTIONAL.repo
[RHELOPT]
name=rhel7serveropt
baseurl=http://xxxxxx.net/x86_64/RedHat/EL7/GA/Server-optional/x86_64/os/
enable=1
gpcheck=0 

另外,配置debuginfo packageyum源:

# cat /etc/yum.repos.d/DEBUG.repo
[RHEL_DEBUG]
name=rhel7server_debug
baseurl=http://xxxxxx.net/x86_64/RedHat/EL7/GA/Server/debug/tree/