KVM移植之ITRON版

KVM虚拟机迁移原理与实践 热迁移环境需要满足的几个必要条件:1.热迁移之前,虚拟机安装文件必须要在源主机和目标主机都可以访问的位置上,并且具有相同的访问路径。实现方式可以是通过独立的NFS共享服务,或者是离线拷贝虚拟机镜像文件到目标主机相同的路径下。2.源主机和目标主机必须可以互相访问(SSH,TCP等协议)。3.迁移过程中经常会出现迁移进度条回滚的现象,这可能就是由迁移算法和逻辑决定的,回滚的目的是迁移上把进度条迁移过程中产生的脏页。 阅读详情

 前段时间由于工作的需要对KVM做了一些研究和学习,最终的目标是要理解KVM的原理和移植要注意的问题,最终拿出一个移植成功的DEMO来。
    说起JAVA也只是在大学里学过一个月,后来写了一个记事本,后来就没怎么碰JAVA了。这次要学习它的解释器有点突然,不过经过努力最终还是实现了预期的目标。
    因为Itron是日本那边用得比较多的嵌入式操作系统,没有文件系统,只有内存管理和任务管理(具体也不是很了解)。庆幸的是KVM实现得很合理,都是用标准C实现的,所以移植起来费的力气并不是很大。
一,文件管理[重新实现标准库函数(fopen,fread,fgetc,feof,fsize,fseek等)]
    鉴于Itron没有文件系统,而KVM的库和CLASS文件允许以ROM的形式一起编译进KVM,同时KVM的文件操作是基于标准C的,这就为我们的移植提供了方便。比方说我们有Hello.java的JAVA程序,这个Hello.java里有一个Hello的类,这个类只做一件是就是输出"Hello World"。我们把它编译成Hello.class之后把这个class文件用其他工具将其转换成二进制数组并存入一个C变量里:HelloClass[]="…"。
    那么我们得重新实现fopen等函数,当KVM在执行打开文件,读取文件等文件操作时将是对HelloClass等类似的数据进行操作(最后给出了一个例子)。这样的话对loader.c就不需要做什么修改了。

二,内存管理
    由于Itron有自己的内存管理,而我也发现在Itron的系统里有C++的new实现。正好,我将它的new实现移植了过来,实现了我们的malloc,calloc,realloc和free函数.代码在最后。

到这里KVM的移植工作基本完成,接下来要做的就是一些优化工作。以上只是一种移植到没有文件系统的操作系统上的解决方案,也是我能想到的最好最快的方案。因为在存储空间有限的嵌入式系统里,有一个文件系统当然会省很多事,但是文件系统的实现或移植并不是一件乘简单的事情。我们当初也考虑过用MSDOS的文件系统,但要在短时间内拿出DEMO来并非易事,所以没有采用。而文件系统在管理文件时也是将文件写在FLASH中,然后对FLASH进行管理,与其这样还不如静态连接入KVM,我觉得采用这套方案是最佳的。可能会有些不便,但是对于应用不多的嵌入式系统来说还是很值得的。
/*
 * Copyright ?2003 Sun Microsystems, Inc. All rights reserved.
 * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
 *
 */

/*=========================================================================
 * KVM
 *=========================================================================
 * SYSTEM: KVM
 * SUBSYSTEM: Itron-specific functions needed by the virtual machine
 * FILE: Hello.h
 * AUTHOR: yangyoufa(blueshycool@gmail.com) (Itron port @2007/04/16)
 *=======================================================================*/

#ifndef __ITRON_HELLO_H__
#define __ITRON_HELLO_H__


static char Helloclass[] = {
   
     0xCA, 0xFE, 0xBA, 0xBE, 0x00, 0x03, 0x00, 0x2D,
     0x00, 0x1D, 0x0A, 0x00, 0x06, 0x00, 0x0F, 0x09,
     0x00, 0x10, 0x00, 0x11, 0x08, 0x00, 0x12, 0x0A,
     0x00, 0x13, 0x00, 0x14, 0x07, 0x00, 0x15, 0x07,
     0x00, 0x16, 0x01, 0x00, 0x06, 0x3C, 0x69, 0x6E,
     0x69, 0x74, 0x3E, 0x01, 0x00, 0x03, 0x28, 0x29,
     0x56, 0x01, 0x00, 0x04, 0x43, 0x6F, 0x64, 0x65,
     0x01, 0x00, 0x0F, 0x4C, 0x69, 0x6E, 0x65, 0x4E,
     0x75, 0x6D, 0x62, 0x65, 0x72, 0x54, 0x61, 0x62,
     0x6C, 0x65, 0x01, 0x00, 0x04, 0x6D, 0x61, 0x69,
     0x6E, 0x01, 0x00, 0x16, 0x28, 0x5B, 0x4C, 0x6A,
     0x61, 0x76, 0x61, 0x2F, 0x6C, 0x61, 0x6E, 0x67,
     0x2F, 0x53, 0x74, 0x72, 0x69, 0x6E, 0x67, 0x3B,
     0x29, 0x56, 0x01, 0x00, 0x0A, 0x53, 0x6F, 0x75,
     0x72, 0x63, 0x65, 0x46, 0x69, 0x6C, 0x65, 0x01,
     0x00, 0x0A, 0x48, 0x65, 0x6C, 0x6C, 0x6F, 0x2E,
     0x6A, 0x61, 0x76, 0x61, 0x0C, 0x00, 0x07, 0x00,
     0x08, 0x07, 0x00, 0x17, 0x0C, 0x00, 0x18, 0x00,
     0x19, 0x01, 0x00, 0x0D, 0x48, 0x65, 0x6C, 0x6C,
     0x6F, 0x20, 0x57, 0x6F, 0x72, 0x6C, 0x64, 0x21,
     0x0A, 0x07, 0x00, 0x1A, 0x0C, 0x00, 0x1B, 0x00,
     0x1C, 0x01, 0x00, 0x05, 0x48, 0x65, 0x6C, 0x6C,
     0x6F, 0x01, 0x00, 0x10, 0x6A, 0x61, 0x76, 0x61,
     0x2F, 0x6C, 0x61, 0x6E, 0x67, 0x2F, 0x4F, 0x62,
     0x6A, 0x65, 0x63, 0x74, 0x01, 0x00, 0x10, 0x6A,
     0x61, 0x76, 0x61, 0x2F, 0x6C, 0x61, 0x6E, 0x67,
     0x2F, 0x53, 0x79, 0x73, 0x74, 0x65, 0x6D, 0x01,
     0x00, 0x03, 0x6F, 0x75, 0x74, 0x01, 0x00, 0x15,
     0x4C, 0x6A, 0x61, 0x76, 0x61, 0x2F, 0x69, 0x6F,
     0x2F, 0x50, 0x72, 0x69, 0x6E, 0x74, 0x53, 0x74,
     0x72, 0x65, 0x61, 0x6D, 0x3B, 0x01, 0x00, 0x13,
     0x6A, 0x61, 0x76, 0x61, 0x2F, 0x69, 0x6F, 0x2F,
     0x50, 0x72, 0x69, 0x6E, 0x74, 0x53, 0x74, 0x72,
     0x65, 0x61, 0x6D, 0x01, 0x00, 0x07, 0x70, 0x72,
     0x69, 0x6E, 0x74, 0x6C, 0x6E, 0x01, 0x00, 0x15,
     0x28, 0x4C, 0x6A, 0x61, 0x76, 0x61, 0x2F, 0x6C,
     0x61, 0x6E, 0x67, 0x2F, 0x53, 0x74, 0x72, 0x69,
     0x6E, 0x67, 0x3B, 0x29, 0x56, 0x00, 0x21, 0x00,
     0x05, 0x00, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00,
     0x02, 0x00, 0x01, 0x00, 0x07, 0x00, 0x08, 0x00,
     0x01, 0x00, 0x09, 0x00, 0x00, 0x00, 0x1D, 0x00,
     0x01, 0x00, 0x01, 0x00, 0x00, 0x00, 0x05, 0x2A,
     0xB7, 0x00, 0x01, 0xB1, 0x00, 0x00, 0x00, 0x01,
     0x00, 0x0A, 0x00, 0x00, 0x00, 0x06, 0x00, 0x01,
     0x00, 0x00, 0x00, 0x01, 0x00, 0x09, 0x00, 0x0B,
     0x00, 0x0C, 0x00, 0x01, 0x00, 0x09, 0x00, 0x00,
     0x00, 0x25, 0x00, 0x02, 0x00, 0x01, 0x00, 0x00,
     0x00, 0x09, 0xB2, 0x00, 0x02, 0x12, 0x03, 0xB6,
     0x00, 0x04, 0xB1, 0x00, 0x00, 0x00, 0x01, 0x00,
     0x0A, 0x00, 0x00, 0x00, 0x0A, 0x00, 0x02, 0x00,
     0x00, 0x00, 0x03, 0x00, 0x08, 0x00, 0x04, 0x00,
     0x01, 0x00, 0x0D, 0x00, 0x00, 0x00, 0x02, 0x00,
     0x0E };

#endif /* __ITRON_HELLO_H__ */

/*
 * Copyright ?2003 Sun Microsystems, Inc. All rights reserved.
 * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
 *
 */

/*=========================================================================
 * KVM
 *=========================================================================
 * SYSTEM: KVM
 * SUBSYSTEM: Itron-specific functions needed by the virtual machine
 * FILE: classes.h
 * AUTHOR: yangyoufa(blueshycool@gmail.com) (Itron port @2007/04/16)
 *=======================================================================*/

#ifndef __ITRON_CLASSES_H__
#define __ITRON_CLASSES_H__

#include "classes/hello.class.h"

/**
 * The type of file, may be class and (jar or zip)
 *
 **/
typedef enum file_type {
    ITRON_UNKNOW = -1,
    ITRON_CLASS = 0,
    ITRON_JAR
} file_type_t;

/**
 * File entry of class or jar package
 *
 **/
typedef struct file_entry {
    const char* filename;
    UI32 size;
    void* data;
    file_type_t type;
} file_entry_t;

/**
 * All entry of files
 **/
static file_entry_t CLASS_FILES[] = {
    {"./Hello.class", sizeof(Helloclass), &Helloclass, ITRON_CLASS},
    {"./HelloHello.class", sizeof(HelloHelloclass), &HelloHelloclass, ITRON_CLASS},
    {NULL, 0, "", ITRON_UNKNOW}
};

#define CLASS_FILES_SIZE (sizeof(CLASS_FILES))
#if 1
#define CLASS_FILES_LEN ((CLASS_FILES_SIZE)/(sizeof(file_entry_t)) - 1 )
#else
#define CLASS_FILES_LEN 1
#endif

#endif /* __ITRON_CLASSES_H__ */


/*
 * Copyright ?2003 Sun Microsystems, Inc. All rights reserved.
 * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
 *
 */

/*=========================================================================
 * KVM
 *=========================================================================
 * SYSTEM: KVM
 * SUBSYSTEM: Itron-specific functions needed by the virtual machine
 * FILE: itron_io.h
 * AUTHOR: yangyoufa(blueshycool@gmail.com) (Itron port @2007/04/13)
 *=======================================================================*/

#ifndef __ITRON_IO_H__
#define __ITRON_IO_H__

#if 0 /* FILE structure */
typedef struct _iobuf {
    unsigned char *_io_next;    /* next character to be read from buffer or
                 next position to put a character in buffer */
    unsigned char *_io_base;    /* start of buffer */
    long _io_left;        /* number of characters left in buffer */
    unsigned _io_channel:14;    /* OS I/O channel number */ /* GWW: was short */
    unsigned _io_ivbuf: 1;    /* the read buffer differs from disk (ungetc called) */
    unsigned _io_append: 1;    /* should do seeks to eof before writing */
    char _io_tmp;        /* used by ungetc on unbuffered files */
    unsigned _io_buffering:2;    /* _IONBF,_IOFBF,_IOLBF */
    unsigned _io_eof: 1;     /* have read end of file */
    unsigned _io_error:1;    /* have detected io error in file */
    unsigned _io_stdio_buffer:1; /* buffer for this file created by stdio */
    unsigned _io_readable:1;    /* file may be read at this time */
    unsigned _io_writable:1;    /* file may be written at this time */
    unsigned _io_readwrite:1;    /* file opened for both reading and writing */
#if __CHAR_BIT > 8
    unsigned _io_binary:1; /* file opened in binary mode */
    unsigned _io_text:1; /* file opened in text mode */
#endif
} FILE;
#endif

/*=========================================================================
 * Include files
 *=======================================================================*/
/* For macros or definitions */
#include <stdio.h>
#include <stdlib.h>

/* RTOS Interface */
#include "mmac/rtos.h"

FILE *itron_fopen(const char *path, const char *mode);
int itron_fclose(FILE *stream);

UI32 itron_fread(void *ptr, UI32 size, UI32 nmemb, FILE *stream);
UI32 itron_fwrite(const void *ptr, UI32 size, UI32 nmemb, FILE* stream);

int itron_fseek(FILE *stream, long offset, int whence);
long itron_ftell(FILE *stream);
int itron_getc(FILE *stream);

#endif /* __ITRON_IO_H__ */


/*
 * Copyright ?2003 Sun Microsystems, Inc. All rights reserved.
 * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
 *
 */

/*=========================================================================
 * KVM
 *=========================================================================
 * SYSTEM: KVM
 * SUBSYSTEM: Itron-specific functions needed by the virtual machine
 * FILE: itron_io.c
 * AUTHOR: yangyoufa(blueshycool@gmail.com) (Itron port @2007/04/13)
 *=======================================================================*/

/*=========================================================================
 * Include files
 *=======================================================================*/
#include "itron_io.h"
#include "itron_mem.h"

#include "classes.h"

#include <global.h>

static file_entry_t* find_entry(const char* path) {
    int i;

    if(path == NULL) {
    return NULL;
    }
   
    for(i=0; i<CLASS_FILES_LEN; i++) {
    if(strcmp(CLASS_FILES[i].filename, path) == 0) {
     return &CLASS_FILES[i];
    }
    }

    return NULL;
}

FILE *itron_fopen(const char *path, const char *mode) {
    FILE* fp;
    file_entry_t* file;
   
    if(path==NULL || mode==NULL) {
    return NULL;
    }

    if( (file = find_entry(path)) != NULL) {
    if((fp = (FILE*) malloc(sizeof(FILE))) != NULL) {
     memset(fp, 0x00, sizeof(FILE));
     fp->_io_base = fp->_io_next = file->data;
   
     fp->_io_left = file->size;

     /*
     fp->_io_channel = 0;
     fp->_io_ivbuf = 0;
     fp->_io_append     = 0;
     fp->_io_tmp        = 0;
     fp->_io_buffering    = 0;
     fp->_io_eof        = 0;
     fp->_io_error    = 0;   
     fp->_io_stdio_buffer= 0;
     */

     /* Read only */
     fp->_io_readable = 1;
     /*
     fp->_io_writable = 0;
     fp->_io_readwrite = 0;
     */

     /* Binary only */
     #if __CHAR_BIT > 8
     fp->_io_binary = 1;
     /*fp->_io_text = 0;*/
            #endif
        
     return fp;
    } else {
     return NULL;
    }
    } else {
    return NULL;
    }
}

int itron_fclose(FILE *stream) {
    if(stream != NULL) {
    free(stream);
    }

    return 0;
}

UI32 itron_fread(void *ptr, UI32 size, UI32 nmemb, FILE *stream) {
    UI32 length;
    FILE* fp = stream;
   
    if(ptr==NULL || size<=0 || nmemb<=0 || stream==NULL) {
    return 0;
    }

    length = size * nmemb;
    if(!fp->_io_eof) { /* Not eof */
    if(length <= fp->_io_left) {
     memcpy(ptr, fp->_io_next, length);
     fp->_io_left -= length;
     fp->_io_next += length;
    } else {
     memcpy(ptr, fp->_io_next, fp->_io_left);
    }

    if(length >= fp->_io_left) {
     fp->_io_eof = 1;
     if(length > fp->_io_left) {
        return 0; /* Or other value */
     }
    }
    } else {
    return -1;
    }

    return nmemb;
}

UI32 itron_fwrite(const void *ptr, UI32 size, UI32 nmemb, FILE* stream) {

}

int itron_fseek(FILE *stream, long offset, int whence) {
    FILE* fp = stream;
    UI32 size;

    if(fp != NULL) {
    size = fp->_io_left + (fp->_io_next - fp->_io_base);
    switch(whence) {
     case SEEK_SET: {/* errors? */
        if(offset < 0) {
         return -1;
        }
        fp->_io_next = (fp->_io_base + offset);
        if(fp->io_next >= fp->_io_base &&
            fp->_io_next <= fp->_io_base + size) {
         fp->_io_left = size - offset;
         return 0;
        }
     }
     break;

     case SEEK_CUR: {
        fp->_io_next += offset;
        if(fp->io_next >= fp->_io_base &&
            fp->_io_next <= fp->_io_base + size) {
         if(offset >= 0) {
            fp->_io_left -= offset;
         } else {
            fp->_io_left += offset;
         }
         return 0;
        }
     }
     break;

     case SEEK_END: {
        if(offset > 0) {
         return -1;
        }
        fp->_io_next -= offset;
        if(fp->io_next >= fp->_io_base &&
            fp->_io_next <= fp->_io_base + size) {
         fp->_io_left += (-1*offset);
         return 0;
        }
     }
     break;

    default:
     break;
    }
    }
   
    return -1;
}

long itron_ftell(FILE *stream) {
    FILE* fp = stream;

    if(fp != NULL) {
    return (fp->_io_next - fp->_io_base);
    }

    return -1;
}

int itron_getc(FILE *stream) {
    char ch;
    FILE* fp = stream;
   

    if(fp != NULL && fp->_io_left) { /* Best */
    ch = (char)(*(fp->_io_next));
    fp->_io_next++;
    fp->_io_left--;
    if(!fp->_io_left) {
     fp->_io_eof = 1;
    }

    return ch;
    }

    return EOF;
}

void itron_rewind(FILE *stream) {
    FILE* fp = stream;
    UI32 size = fp->_io_left + (fp->_io_next - fp->_io_base);
   
    if(fp == NULL) {
    return ;
    }
   
    fp->_io_next = fp->_io_base;

    fp->_io_left = size;

    fp->_io_eof = 0;
/*fp->_io_channel = 0;
  fp->_io_ivbuf = 0;
  fp->_io_append     = 0;
  fp->_io_tmp        = 0;
  fp->_io_buffering    = 0;
  fp->_io_eof        = 0;
  fp->_io_error    = 0;   
  fp->_io_stdio_buffer= 0;
 */

 /* Read only */
 fp->_io_readable = 1;
 /*
 fp->_io_writable = 0;
 fp->_io_readwrite = 0;
 */
 /* Binary only */
 #if __CHAR_BIT > 8
 fp->_io_binary = 1;
 /*fp->_io_text = 0;*/
 #endif
}

UI32 itron_fsize(FILE* fp) {
    if(fp != NULL) {
        return (fp->_io_left + (fp->_io_next - fp->_io_base));
    }

    return -1;
}
/* 当然我们得对global.h做些相应的修改,就是将标准库函数的调用指向我们自己的实现如:

#ifdef ITRON /* Reimplemention of file I/O functions (Add @2007/04/16 by yangyoufa) */
#define fopen itron_fopen
#define fclose itron_fclose
#define fread itron_fread
#define fwrite itron_fwrite
#define fseek itron_fseek
#define ftell itron_ftell
#define getc itron_getc
#define rewind itron_rewind

#define malloc itron_malloc
#define calloc itron_calloc
#define realloc itron_realloc
#define free itron_free
#endif

*/

/*
 * Copyright ?2003 Sun Microsystems, Inc. All rights reserved.
 * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
 *
 */

/*=========================================================================
 * KVM
 *=========================================================================
 * SYSTEM: KVM
 * SUBSYSTEM: Itron-specific functions needed by the virtual machine
 * FILE: itron_mem.h
 * AUTHOR: yangyoufa(blueshycool@gmail.com) (Itron port @2007/04/16)
 *=======================================================================*/

#ifndef __ITRON_MEM_H__
#define __ITRON_MEM_H__

/*=========================================================================
 * Include files
 *=======================================================================*/
#include "mmac/rtos.h" /* RTOS Interface */

/*=========================================================================
 * FUNCTION:    allocates memory for an array of nmemb elements of size
 *                bytes each and returns a pointer to the allocated memory.
 *                The memory is set to zero.
 * TYPE: Memory control
 * OVERVIEW:   
 * INTERFACE
 * parameters:    nmemb    members
 *                    size    the size of array
 * returns:        If success returns a pointer to the start address of
 *                    the array, or NULL when fail.
 *=======================================================================*/
void *itron_calloc(UI32 nmemb, UI32 size);

/*=========================================================================
 * FUNCTION:    allocates size bytes and returns a pointer to the
 *                allocated memory. The memory is not cleared.
 *
 * TYPE: Memory control
 * OVERVIEW:   
 * INTERFACE
 * parameters:    size    the size of array
 * returns:        If success returns a pointer to the start address of
 *                    the array, or NULL when fail.
 *=======================================================================*/
void *itron_malloc(UI32 size);

/*=========================================================================
 * FUNCTION:    frees the memory space pointed to by ptr, which must have
 *                been returned by a previous call to malloc(), calloc() or
 *                realloc(). Other- wise, or if free(ptr) has already
 *                been called before, undefined behaviour occurs.
 *                If ptr is NULL, no operation is performed.
 *
 * TYPE: Memory control
 * OVERVIEW:   
 * INTERFACE
 * parameters:    ptr The start address of memory will be freed.
 * returns:       
 *=======================================================================*/
void itron_free(void *ptr);

/*=========================================================================
 * FUNCTION:    changes the size of the memory block pointed to by ptr to
 *                size bytes. The contents will be unchanged to the minimum
 *                of the old and new sizes; newly allocated memory will be
 *                uninitialized. If ptr is NULL, the call is equivalent to
 *                malloc(size); if size is equal to zero, the call is
 *                equivalent to free(ptr). Unless ptr is NULL, it must have
 *                been returned by an earlier call to malloc(), calloc() or
 *                realloc().
 *
 * TYPE: Memory control
 * OVERVIEW:   
 * INTERFACE
 * parameters:    ptr The start address of memory will be freed.
 *                    size the new size of array
 * returns:       
 *=======================================================================*/
void *itron_realloc(void *ptr, UI32 size);


#endif /* __ITRON_IO_H__ */

/*
 * Copyright ?2003 Sun Microsystems, Inc. All rights reserved.
 * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
 *
 */

/*=========================================================================
 * KVM
 *=========================================================================
 * SYSTEM: KVM
 * SUBSYSTEM: Itron-specific functions needed by the virtual machine
 * FILE: itron_mem.h
 * AUTHOR: yangyoufa(blueshycool@gmail.com) (Itron port @2007/04/16)
 *=======================================================================*/

/*=========================================================================
 * Include files
 *=======================================================================*/
#include "itron_mem.h"
#include "mmac/rtos.h" /* RTOS Interface */

/****************************************************************/
/* MACROS/DEFINES */
/****************************************************************/

#ifdef ITRON
#define ASSERT(x) assert(x)
#else
#define ASSERT(x)
#endif

#define DYNAMIC_POOL_SIZE (0x80000)
#define POOL_OVERHEAD_SIZE (0x20)
#define ALLOC_OVERHEAD_SIZE (0x00)

#define MIN_BLOCK_ALLOCATION (0)


extern MMAC_RTOS_MEMORY_POOL RTOS_systemHeap;
MMAC_RTOS_MEMORY_POOL localPool = 0;

static void* itron_getmem (UI32 sizeInBytes)
{
    MMAC_RTOS_RESULT_CODE result;
    void * memoryBlock;
    char * pFreeMemory;

#if 0
    if (0 == localPool)
    {
        result = MMAC_RTOS_AllocMemory (RTOS_systemHeap,
                                        DYNAMIC_POOL_SIZE +
                                        POOL_OVERHEAD_SIZE +
                                        ALLOC_OVERHEAD_SIZE,
                                        ((void**)&pFreeMemory));
        ASSERT (MMAC_RTOS_OK == result);

        localPool = (MMAC_RTOS_MEMORY_POOL) pFreeMemory;

        pFreeMemory += POOL_OVERHEAD_SIZE;

        result = MMAC_RTOS_CreateMemoryPool ((I8*)"kvmHeap",
                                             pFreeMemory,
                                             DYNAMIC_POOL_SIZE,
                                             MIN_BLOCK_ALLOCATION,
                                             localPool);
        ASSERT (MMAC_RTOS_OK == result);
    }
   
    result = MMAC_RTOS_AllocMemory (localPool, sizeInBytes, (void**)&memoryBlock);
    if (MMAC_RTOS_OK != result)
    {
        memoryBlock = NULL;
    }
#endif
    result = MMAC_RTOS_AllocMemory (RTOS_systemHeap, sizeInBytes, (void**)&memoryBlock);
    ASSERT (MMAC_RTOS_OK == result);

#if (MMAC_ICE_OPERATOR_RESULT_DEBUG_ENABLE == MMAC_YES)
    MMAC_DEBUG_Print(MMAC_DEBUG_MSG, "localGetMemory: memoryBlock = 0x%x/n/r", memoryBlock);
#endif
    return memoryBlock;
}

static void itron_freemem (void * memPtr)
{
    MMAC_RTOS_RESULT_CODE result;

#if (MMAC_ICE_OPERATOR_FUNCTION_DEBUG_ENABLE == MMAC_YES)
    MMAC_DEBUG_Print(MMAC_DEBUG_MSG, "localFreeMemory: memPtr = 0x%x/n/r", memPtr);
#endif
    if(memPtr != NULL)
    {
     result = MMAC_RTOS_FreeMemory (memPtr);
        ASSERT (MMAC_RTOS_OK == result);
    }

    return;
}

/*=========================================================================
 * FUNCTION:    allocates memory for an array of nmemb elements of size
 *                bytes each and returns a pointer to the allocated memory.
 *                The memory is set to zero.
 * TYPE: Memory control
 * OVERVIEW:   
 * INTERFACE
 * parameters:    nmemb    members
 *                    size    the size of array
 * returns:        If success returns a pointer to the start address of
 *                    the array, or NULL when fail.
 *=======================================================================*/
void *itron_calloc(UI32 nmemb, UI32 size) {
    void* mem;
    UI32 length;

    if(nmemb<=0 || size<=0) {
    return NULL;
    }

    length = nmemb * size;
    mem = itron_getmem(length );
    if(mem != NULL) {
    memset(mem, 0x00, length);
    return mem;
    }

    return NULL;
}

/*=========================================================================
 * FUNCTION:    allocates size bytes and returns a pointer to the
 *                allocated memory. The memory is not cleared.
 *
 * TYPE: Memory control
 * OVERVIEW:   
 * INTERFACE
 * parameters:    size    the size of array
 * returns:        If success returns a pointer to the start address of
 *                    the array, or NULL when fail.
 *=======================================================================*/
void *itron_malloc(UI32 size) {
    if(size<=0) {
    return NULL;
    }

    return itron_getmem(size );
}

/*=========================================================================
 * FUNCTION:    frees the memory space pointed to by ptr, which must have
 *                been returned by a previous call to malloc(), calloc() or
 *                realloc(). Other- wise, or if free(ptr) has already
 *                been called before, undefined behaviour occurs.
 *                If ptr is NULL, no operation is performed.
 *
 * TYPE: Memory control
 * OVERVIEW:   
 * INTERFACE
 * parameters:    ptr The start address of memory will be freed.
 * returns:       
 *=======================================================================*/
void itron_free(void *ptr) {
    if(ptr != NULL) {
    itron_freemem(ptr);
    }
}

/*=========================================================================
 * FUNCTION:    changes the size of the memory block pointed to by ptr to
 *                size bytes. The contents will be unchanged to the minimum
 *                of the old and new sizes; newly allocated memory will be
 *                uninitialized. If ptr is NULL, the call is equivalent to
 *                malloc(size); if size is equal to zero, the call is
 *                equivalent to free(ptr). Unless ptr is NULL, it must have
 *                been returned by an earlier call to malloc(), calloc() or
 *                realloc().
 *
 * TYPE: Memory control
 * OVERVIEW:   
 * INTERFACE
 * parameters:    ptr The start address of memory will be freed.
 *                    size the new size of array
 * returns:       
 *=======================================================================*/
void *itron_realloc(void *ptr, UI32 size) {
    return realloc(ptr, size); /* Not support current */
}

KVM克隆及在不同物理机下的移植 KVM 虚拟机的管理工具  准确来说,KVM 仅仅是 Linux 内核的一个模块。管理和创建完整的 KVM 虚拟机,需要更多的辅助工具 QEMU-KVM在 Linux 系统中,首先我们可以用 modprobe 系统工具去加载 KVM 模块,如果用 RPM 安装 KVM 软件包,系统会在启动时自动加载模块。 加载了模块后,才能进一步通过其他工具创建虚拟机。但仅有 KVM 模块是远远不够的,因为用户无法 阅读详情

相关推荐

KVM虚拟化技术

KVM(名称来自英语:Kernel-basedVirtual Machine的缩写,即基于内核的虚拟机),是一种用于Linux内核中的虚拟化基础设施,可以将Linux内核转化为一个hypervisor。KVM在2007年2月被导入Linux 2.6.20核心中,以可加载核心模块的方式被移植到FreeBSD及illumos上。KVM在具备Intel VT或AMD-V功能的x86平台上运行。它也被移植到S/390,PowerPC与IA-64平台上。在Linux内核3.9版中,加入ARM架构的支持。

m0_74282605的博客 1255

ITRON系统使用方法

本文档有些图片不能显示出来,可以到我资源里面下载完整文档。 ITRON系统使用方法    目录 1    引言.... 4 2    ITRON系统介绍.... 5 2.1     概要... 5 2.2     构成... 5 2.2.1   ITRON系统构成... 5 2.2.2   ITRON体系结构... 5 2.3     应用领域.

Leo 9465

基于ITRON标准的RTOS的原理和应用

基于ITRON标准的RTOS的原理和应用,学习ITRON的好教材,不过是日本人搞的,哎,没办法啊

iTron3学习笔记(一) System Calls of Memory Pool Management Functions

iTron3学习笔记(一)  System Calls of Memory Pool Management Functions1、创建固定内存池(Create Fixed Memory Pool)说明:在RAM中的固定位置,创建一块内存池。函数声明:ER vcre_mpf(ID  mpfid,VP  start_addr,VP  end_addr,INT blfsz)参数说明:    ID  mp

Larry的专栏 942

Itron系统说明

Itron系统

t-kernel移植手册

一个非常有价值的t-kernel的移植手册,详细的描述了哪些文件需要修改

宋宝华- KVM最初的2小时(KVM从入门到入不了门)

接着《Docker最初的2小时(Docker从入门到入门)》继续聊,再花10个小时写出《KVM最初的2小时(KVM从入门到入不了门)》。坦白讲,由于KVM远远比Docker要复杂,还是要2小时爱上KVM,这绝非难事,所以很可能入不了门。原则上,我们继续迭代学习,这篇文章建立你对KVM的最好初印象,但是绝不深入细节。

宋宝华 2万+

KVM在嵌入式Linux上的移植

目前嵌入式Linux被广泛应用于嵌入式设备,Java语言由于其"Write Once,Run Anywhere"的特性,开始被应用于掌上电脑、智能手机等嵌入式系统。

kvm文档翻译-第一章

说明 翻译KVM的文档,只是为了个人学习以做记录.如果有翻译不周到的地方,请指出,我会修正的. 为何翻译该文档 此KVM不是目前特别火的Kernel-based Virtual Machine(一个开源的系统虚拟化模块).而是一个JAVA 的虚拟机.是J2ME cldc 的一个实现.其源码的难度比hotspot简单多了.因此,想通过研读KVM,以加深对hotspot的理解 关于这个文档 本文档提供...

qq_26000415的博客 5655

用户存续期价值评估CLV(二) BG/NBD Model python模拟

BG/NBD Model …继续 想象每一个客户有两个硬币,一个“Buy Coin"控制客户购买的概率;一个"Die Coin"控制客户流失、不再购买的概率。 前面假设了客户的交易次数服从泊松过程: 在一年中的每个月,客户都以抛硬币的方式来决定是否购买。我们所观察到的购买次数取决与泊松分布的参数 ????。 %matplotlib inline import numpy as np impor...

weixin_43171270的博客 3426

论文理解【LLM-OR】——【Step-Opt】Training LLMs for Optimization Modeling via Iterative Data Synthesis and

本文提出 Step-Opt-Instruct 方法,针对用 LLM 做 OR 问题求解任务,用迭代问题生成 + 分步验证机制实习更可靠的训练数据合成,从而微调开源 LLM 得到 Step-Opt。在多个 OR 建模基准提升性能,尤其在复杂问题上提升更明显

佚失的诗篇 805

【引用】Linux应用程序开发(三)---移植kvm到arm linux

移植环境(红色粗字体字为修改后内容,蓝色粗体字为特别注意内容) 1,主机环境:VMare下CentOS 5.5 ,1G内存。 2,集成开发环境:Elipse IDE 3,编译编译环境:arm-linux-gcc v4.4.3,arm-none-linux-gn?i-gcc v4.5.1。 4,开发板:mini2440,2M nor flash,128M nand flash。 5,u-b

liuqiang_mail的专栏 1624

SAP公司间外协业务流程以及配置说明

SAP公司间外协业务流程以及配置说明

竹大的博客 7166

KVM虚拟化

kvm主机部署、webvirtmgr部署、kvm实例管理

你看月亮好美的博客 4341

从零构建:用Simulink搭建固定翼无人机六自由度模型的避坑指南

本文详细介绍了使用Simulink从零构建固定翼无人机六自由度动力学模型的完整流程和避坑指南。重点解析了模型架构设计、气动力计算、参数配置、仿真求解器选择等关键环节的常见问题与解决方案,帮助开发者快速建立准确可靠的无人机控制系统仿真模型。

hhh00的博客 999

基于RK3588与Gstreamer的端侧实时视频流AI推理系统构建

本文详细介绍了基于RK3588芯片与Gstreamer框架构建端侧实时视频流AI推理系统的完整方案。通过硬件选型、环境配置、OpenCV编译优化、视频流处理实战及模型部署等关键环节的深入解析,展示了如何利用RK3588的6TOPS NPU算力与Gstreamer的低延迟特性,实现工业质检、智能交通等场景下的高效边缘计算。特别针对RTSP推拉流优化、RKNN模型转换等核心技术难点提供了实用解决方案。

weixin_30516243的博客 381

Linux部署KVM虚拟化平台_linux kvm(1)

最全的Linux教程,Linux从入门到精通第一份《Linux从入门到精通》466页内容简介====本书是获得了很多读者好评的Linux经典畅销书**《Linux从入门到精通》的第2版**。本书第1版出版后曾经多次印刷,并被51CTO读书频道评为“最受读者喜爱的原创IT技术图书奖”。本书第﹖版以最新的Ubuntu 12.04为版本,循序渐进地向读者介绍了Linux 的基础应用、系统管理、网络应用、娱乐和办公、程序开发、服务器配置、系统安全等。本书附带1张光盘,内容为本书配套多媒体教学视频。

m0_62261166的博客 646

黑猫带你学UFS协议第12篇:UFS标志(Flags)和属性(Atrributes)详解

UFS中的标志其实就是一些开关,布尔型,非0即1,打开或者关闭。这些标志可以用来使能或者禁止UFS设备的一些功能、模式或者状态。 简单来说,flag和attribute、discriptor一样,都是ufs的寄存器罢了。只不过spec将这些寄存器分类了,分成这三种大的类型了而已。 标志可以被清除、复位、设置、触发、读。 主机也是通过设备管理器的Query Request UPIU来读取或者写标志。

黑猫奥利奥的博客 2083

KVM Porting 指南

 英文原名:KVM Porting Guide (KVM 1.0.3)    翻译:Ding  E-mail:wu_yi_ding@yahoo.com   本文是j2me_cldc-1_0_3附带的KVM Porting Guide的翻译,对移植KVM到特定 的平台上很有参考价值。原书有100多页,我尽量把它译完,但时间有限,能否完 成我也无法确保。希望对有志于

碧血妖狐 1058

UG NX二次开发-博客文章速览

写了一些UG NX二次开发的心得体会,内容较多,感觉不好查找相应的内容,所以决心把导航写出来,方便自己也方便读者。主专栏是“”,C#专栏为 : “” ,Python专栏为 : “这三个专栏都会持续的更新。如果有需要咨询或者学习讨论的,请私信博主或者加QQ群:749492565。博主几乎每天都在。

GimiGimmy 3714

RK3399驱动开发 | 19 - 阿美林7寸mipi屏幕调试(基于linux4.4.194内核)

NULL

Mculover666的博客(嵌入式) 2661
上一篇: KVM在嵌入式μCLinux操作系统上的移植
下一篇: tekkamanninja's tslib-1.4 移植记录
vrix
博客等级 码龄24年 673粉丝 167原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值